[RESOLVED] Checkbox control on content page
How can I access a checkbox control on a content page if I know the checkbox’s ID?
I have tried the code below, but using Me.Controls does not seam to generate a controls collection beyond the MasterPage… or I am way off target and have not figured it out yet.
Thanks for your help in advance.
Code:
Dim ctr As Control
Dim s as String
For Each s In Str_ArrayList ‘these are the checkbox IDs
For Each ctr In Me.Controls
If ctr.ID = s Then
CType(ctr, CheckBox).Checked = True
End If
Next
Next
Re: Checkbox control on content page
As you have placed control inside the Content place holder try the
Code:
Me.ContentPlaceHolder.Controls method
Re: Checkbox control on content page
That did the trick. Thanks for the tip. :)
Code:
Dim contentPlaceHolder As ContentPlaceHolder
contentPlaceHolder = CType(Page.Master.FindControl("ContentPlaceHolder1"), WebControls.ContentPlaceHolder)
Dim ctr As Control
For Each s In Str_ArrayList
For Each ctr In contentPlaceHolder.Controls
If ctr.ID = s Then
CType(ctr, CheckBox).Checked = True
End If
Next
Next
Re: [RESOLVED] Checkbox control on content page
Why not just reference it by its ID name in the codebehind, as that's going to be available to you for all the controls.
Re: [RESOLVED] Checkbox control on content page
The control names are pulled from a database at runtime (when the page is loaded). If there was a way to directly reference the controls with a variable name, I would prefer to do that. A direct reference has to be more efficient than looping through all the controls (> 150 checkboxes alone) each time, although this event does not occur that often.