PDA

Click to See Complete Forum and Search --> : Control not being found when looping through controls


greg_quinn
Nov 11th, 2004, 03:08 AM
I am looping through all the dynamic controls in a form, if the control ID begins with an 'o', I know it is a certain type of radiobutton, and I need to see if it is checked or not. But my code below gives me the error

What is wrong with my code below?

For each pageControl in pollForm.Controls
' If the control id begins with 'o' it is an optional radiobutton

If Mid(pageControl.ID, 1, 1) = "o" Then
myControl = Page.FindControl(pageControl.ID) ' ...object reference not set to an instance of an object.
End If

If myControl.Checked Then
Response.Write("The control was checked")
End If
Next

nemaroller
Nov 11th, 2004, 06:49 AM
A simpler way may be to just add an Attribute to the control after you create it, and search for the existence of that attribute.