Results 1 to 6 of 6

Thread: [Resolved] FindControl() to find a Programmatically Added Control?

Threaded View

  1. #1

    Thread Starter
    Fanatic Member Redth's Avatar
    Join Date
    May 2001
    Location
    Ontario, Canada
    Posts
    551

    [Resolved] FindControl() to find a Programmatically Added Control?

    Hey guys, I've got a page that dynamically adds textboxes to a page. well, i sort of do it in a loop... i have i, and for whatever i contains, i add controls like this:

    VB Code:
    1. For i = 0 To lstColumns.Items.Count - 1
    2.  
    3.             Dim tRow As New TableRow()
    4.             Dim tCell1 As New TableCell()
    5.            
    6.             Dim newTextBox As New TextBox()
    7.             newTextBox.ID = "txtDG_" & i
    8.             newTextBox.Text = "Blah"
    9.  
    10.             tCell1.Controls.Add(newTextBox)
    11.  
    12.             tRow.Cells.Add(tCell1)
    13.        
    14.             tblEdit.Rows.Add(tRow)
    15. Next

    Now, this works peachy, and my textboxes all appear, and it's just great, however, i do need to later retreive their values... so lets say i do something like this:

    VB Code:
    1. For i = 0 to lstColumns.Items.Count - 1
    2.            Response.Write(CType(FindControl("txtDG_" & i), TextBox).Text)
    3. Next

    This should work, should it not? At least one would think.. neways, here's the error i'm getting:

    Object reference not set to an instance of an object.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    Line 180:
    Line 181: For i = 0 To lstColumns.Items.Count - 1
    Line 182: Response.Write(CType(FindControl("txtDG_" & i), TextBox).Text)
    Line 183: Next
    Line 184:
    Last edited by Redth; Jan 19th, 2003 at 11:21 PM.

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