|
-
Jun 11th, 2009, 07:33 PM
#1
Thread Starter
Lively Member
[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
-
Jun 12th, 2009, 12:03 AM
#2
Re: Checkbox control on content page
As you have placed control inside the Content place holder try the
Code:
Me.ContentPlaceHolder.Controls method
Please mark you thread resolved using the Thread Tools as shown
-
Jun 12th, 2009, 01:34 PM
#3
Thread Starter
Lively Member
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
-
Jun 14th, 2009, 03:59 PM
#4
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.
-
Jun 15th, 2009, 06:03 AM
#5
Thread Starter
Lively Member
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.
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
|