Accessing ContentPlaceHolder2 Controls from ContentPlaceHolder1

bobw2829

Member
Joined
May 25, 2007
Messages
7
Programming Experience
3-5
Hi All,

I've hit a wall here and can't figure what's the problem. I have created a master page with 2 ContentPlaceHolders, (ContentPlaceHolder1, ContentPlaceHolder2). ContentPlaceHolder1 contains a form that when submitted is suppose to display results through GridView in ContentPlaceHolder2. My problem is, I can't access the GridView in ContentPlaceHolder2 from ContentPlaceHolder1 Business Layer. When I do an output I can see the recursive function can access ContentPlaceHolder2, but can't get at any of it's controls.

Here's the output:

ContentPlaceHolder1
PageMessage
txtSearchBox
SearchButton
AdvancedSearch
CloseButton
txtDomain
txtSearchClass
txtSearchStr
txtSearchType
ContentPlaceHolder2

As you can see, each control from ContentPlaceHolder1 is displayed, but none from ContentPlaceHolder2.

Here's the code:

VB.NET:
            For Each ctrl As Control In Me.Master.Page.Form.Controls
                If ctrl.GetType Is GetType(ContentPlaceHolder) Then
                    MySession.Message = MySession.Message + ctrl.ID.ToString + "<br>"
                    recurseControl(ctrl)
                End If
            Next

~~~

    Protected Sub recurseControl(ByVal control As Control)
        For Each ctrl As Control In control.Controls
            If Not ctrl.ID Is Nothing Then
                MySession.Message = MySession.Message + "   " + ctrl.ID.ToString + "<br>"
            End If
            If ctrl.HasControls Then
                MySession.Message = MySession.Message + " Has More Controls!!!<br>"
                recurseControl(ctrl)
            End If
        Next
    End Sub

The code is using a recursive function to loop through ContentPlaceHolder controls and adds control ID to MySession.Message.

Any help would surely be appreciated.
 
Back
Top