|
-
Jan 19th, 2003, 10:08 PM
#1
Thread Starter
Fanatic Member
[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:
For i = 0 To lstColumns.Items.Count - 1
Dim tRow As New TableRow()
Dim tCell1 As New TableCell()
Dim newTextBox As New TextBox()
newTextBox.ID = "txtDG_" & i
newTextBox.Text = "Blah"
tCell1.Controls.Add(newTextBox)
tRow.Cells.Add(tCell1)
tblEdit.Rows.Add(tRow)
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:
For i = 0 to lstColumns.Items.Count - 1
Response.Write(CType(FindControl("txtDG_" & i), TextBox).Text)
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|