Link to home
Start Free TrialLog in
Avatar of Robert Treadwell
Robert TreadwellFlag for United States of America

asked on

Nested MasterPages FindControl TextBox.

In the following code and am trying to retrieve the text from a textbox from a child masterpage. The code returns a null value, I'm unsure why this returns null because in debug mode I am able to see value entered.
 
Parent Master:
                <!-- Content Body Holder -->
                <div style="border-width: 1em; border-color: #000;">
                    <asp:ContentPlaceHolder id="defaultBodyCPH" runat="server"></asp:ContentPlaceHolder>
                </div>

Child Master:
<asp:Content ID="Content2" ContentPlaceHolderID="defaultHeaderCPH" Runat="Server">
                    <!--This section contains the Website Search functionality -->
                    <div style="float: right; background:#fff; border:solid .1em #000;">
                        <asp:Textbox id="searchTB" runat="server" width="20em" height="2.25em" cssClass="searchBox" OnTextChanged="Search" />
                        <asp:ImageButton id="cmdSearch" runat="server" ImageUrl="~/images/searchIcon.png" ImageAlign="Middle" style="margin-left: -.5em;" onclick="Search"/>
                        <asp:textboxwatermarkextender runat="server" ID="searchTBWE" TargetControlID="searchTB" WatermarkText="Enter Search Criteria" WatermarkCssClass="watermarked" />
                    </div>
</asp:Content>

Codebehind:
'This code works in conjunction with the Event handler in the ListViewMasterPage VB code
            Dim masterPage As MasterPages_ListViewMasterPage = TryCast(Me.Master, MasterPages_ListViewMasterPage)
            Dim cp As ContentPlaceHolder = CType(Me.Master.Master.FindControl("defaultBodyCPH"), ContentPlaceHolder)
            'Dim db As ClientInfoDataContext = New ClientInfoDataContext
            Dim search As String
            If Not IsNothing(masterPage) Then
                Dim searchTBx As TextBox = CType(cp.FindControl("searchTB"), TextBox)
                search = searchTBx.Text
            End If
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial