Results 1 to 5 of 5

Thread: [RESOLVED] Checkbox control on content page

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    88

    Resolved [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

  2. #2
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    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

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    88

    Thumbs up 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

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    88

    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
  •  



Click Here to Expand Forum to Full Width