adding server controls programmaticly
In the page load sub, I am adding a checkbox to a table cell with the following code:
Dim chkNewCheckbox As New CheckBox()
tblMyTable.Rows(0).Cells(0).Controls.Add(chkNewCheckBox)
The control adds and displays OK but when I try to use it in any fashion by employing the findcontrol method, I get a error msg that reads 'Object reference not set to an instance of an object.'
The code that I'm using to locate the control looks like this:
Dim chkYourCheckbox As CheckBox = CType(tblMyTable.Rows(0).Cells(0).FindControl("chkNewCheckbox"), CheckBox)
If (chkYourCheckbox.Checked = True) Then
Response.Write("Checked")
Else
Response.Write("UNChecked")
End If
Anybody have experience with this situation?
In general, I'm having problems getting access to the methods and properties of child controls. What is the .NET methodology for getting such access?