|
-
Dec 23rd, 2002, 07:15 PM
#1
Thread Starter
New Member
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?
-
Dec 30th, 2002, 04:01 AM
#2
New Member
You need to put an identifier on it.
Instead do something like
Dim chkNewCheckbox As New CheckBox()
'Set the id attribute so that find control can look for something.
chkNewCheckbox.ID = "chkNewCheckbox"
Then you can use findcontrol.
Also, below your class declaration you can do something like:
Private chkNewCheckbox As New CheckBox
and you can access this checkbox from any method in your code.
- Justin_
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
|