Re: Loop through controls with MaterPage ContentHolder

From: Scott Allen (bitmask_at_[nospam)
Date: 09/25/04


Date: Sat, 25 Sep 2004 09:59:56 -0400

Hi sck10:

The hierarchy of controls with MasterPages looks like this:

Page
 - MasterPage
   - HtmlForm
     - ContentPlaceHolder
       - The TextBoxes, etc.

So your logic could look something like the following.

For Each ctlMaster As Control In Page.Controls
   If TypeOf ctlMaster Is MasterPage Then
      For Each ctlForm As Control In ctlMaster.Controls
         If TypeOf ctlForm Is HtmlForm Then
            For Each ctlContent As Control In ctlForm.Controls
               If TypeOf ctlContent Is ContentPlaceHolder Then
                  For Each ctlChild As Control In ctlContent.Controls
                 ' Do work...
                  Next
               End If
            Next
         End If
      Next
   End If
Next

--
Scott
http://www.OdeToCode.com
On Fri, 24 Sep 2004 09:02:19 -0700, "sck10" <sck10@online.nospam>
wrote:
>I changed my aspx page to use a master page.  The problem is that I can no 
>longer loop through the controls on the content page.  My question is how do 
>you loop through the controls on the master page and how do you loop through 
>the controls on the content page when the content is inside the ContentHolder 
>control?
>
>Below is an example of the control loop before using a master page.
>
>Sub FindControlsInWebForm()
>Dim strValue As String = ""
>
>'Loop through controls
>For Each ctlPage As Control In Page.Controls
>  If TypeOf ctlPage Is HtmlForm Then
>    For Each ctlChild As Control In ctlPage.Controls
>      If TypeOf ctlChild Is Label Then strValue &= "Page.Label.ID = " &
>ctlChild.ID & ".ID<br>"
>
>'Panel
>      If TypeOf ctlChild Is Panel Then
>        strValue = "Panel.ID = " & ctlChild.ID & ".ID<br>"
>
>        For Each ctlGrndChild As Control In ctlChild.Controls
>          If TypeOf ctlGrndChild Is TextBox Then strValue &=
>"Panel.TextBox.ID = " & ctlGrndChild.ID & ".ID<br>"
>        Next ctlGrndChild
>      End If
>    Next ctlChild
>  End If
>Next ctlPage
>End Sub


Relevant Pages

  • Re: asp.net 2.0 master pages problem
    ... >Scott, your closing statement is not neccessarily correct when controls are ... >> Page_Load for both the content page and the master). ... I think the Calendar is a bit quirky in this respect. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Trouble with Javascript when converting 2003 webproject to a 2005 project using Master Pages
    ... this will be the server-side form created by default in the master ... > controls in a form in the page. ... The form name is "frmContent", ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: ASP.net 2 Master pages menu and saving pages - Weired situation - please help
    ... The only downside here is if you use autopostback instead of AJAX on certain controls. ... But, if you want to just automatically save the stuff, then your nav links in your master page will have to be linkbuttons which will post and execute whatever code is necessary in each of your pages in the Page_Load in an ifblock. ... The problem that I have is that once the users are selecting ... IManageable that the base class implements it. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: asp.net 2.0 master pages problem
    ... your closing statement is not neccessarily correct when controls are ... > The SelectedDate property of the Calendar will not be updated until ... > Page_Load for both the content page and the master). ... I think the Calendar is a bit quirky in this respect. ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Still no sound. I have a Dell Demension 2350 and a Intel 82801Soundcard.
    ... All the sliders are off zero and unmuted, not just master volume, none are that high, but my speakers are turned up so load, the kids in the dorm building over are going to be angry when I finally here this test sound. ... Did you turn all of the volume controls up or just the master volume? ... alias usb-controller ehci-hcd ...
    (Fedora)