Results 1 to 3 of 3

Thread: [RESOLVED] findcontrol = finding textbox in a table row

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Posts
    407

    Resolved [RESOLVED] findcontrol = finding textbox in a table row

    HI Guys,

    When I add a textbox to my table cell then then add the table cell to the table row. Then I try access that control it always comes back null.

    Code:
            newTextBox = new TextBox();
            newTextBox.ID = "row_1Col_1";
            newTextBox.Font.Size = FontUnit.Medium;
            newTextBox.Width = 70;
            newTextBox.Text = "Blah"                              
            acell.Controls.Add(newTextBox);
            arow.Cells.Add(acell);
    After the last line of code I break and try a quick watch.
    acell.FindControl("row_1Col_1") which comes back null
    I also try
    arow.FindControl("row_1Col_1") which also comes back null.

    before this code I do a quick watch on arow.controls.count which comes back as 0, then after the code I do the same thing and it comes back as 1. So I know it's getting added, but can't seem to get back to the textbox value.

    is there a way to list all the controls or something? Because I think it changes the name or something.

    I know this code is in C#, but it's the same idea in VB. IF I'm wrong please redirect the post to the right thread thanks.
    My Websites
    SharpMP3 - MP3 Design Articles www.sharpmp3.com
    Yobbers - Job Search www.yobbers.com
    Lets Trend - Methods For Riding Stock Trends www.letstrend.com

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Posts
    407

    Re: findcontrol = finding textbox in a table row

    Actually I just found this. If I do this:

    HTML Code:
    Control ctrl = arow.Cells[1].Controls[0];
    TextBox tc = ctrl as TextBox;
    After arow.Cells.Add(acell);
    Then I get my textbox. So I'll just do it this way, but still not sure why findcontrol doesn't work. Any ideas?
    My Websites
    SharpMP3 - MP3 Design Articles www.sharpmp3.com
    Yobbers - Job Search www.yobbers.com
    Lets Trend - Methods For Riding Stock Trends www.letstrend.com

  3. #3
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: findcontrol = finding textbox in a table row

    Hello,

    The only thing that I can think is that the ID wasn't being found. From what I can see, it "should" have worked.

    Glad to got it working though, can you remember to mark your thread as Resolved?

    Thanks

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width