Robert Treadwell
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:Conte ntPlaceHol der>
</div>
Child Master:
<asp:Content ID="Content2" ContentPlaceHolderID="defa ultHeaderC PH" 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/searchI con.png" ImageAlign="Middle" style="margin-left: -.5em;" onclick="Search"/>
<asp:textboxwatermarkexten der runat="server" ID="searchTBWE" TargetControlID="searchTB" WatermarkText="Enter Search Criteria" WatermarkCssClass="waterma rked" />
</div>
</asp:Content>
Codebehind:
'This code works in conjunction with the Event handler in the ListViewMasterPage VB code
Dim masterPage As MasterPages_ListViewMaster Page = TryCast(Me.Master, MasterPages_ListViewMaster Page)
Dim cp As ContentPlaceHolder = CType(Me.Master.Master.Fin dControl(" defaultBod yCPH"), ContentPlaceHolder)
'Dim db As ClientInfoDataContext = New ClientInfoDataContext
Dim search As String
If Not IsNothing(masterPage) Then
Dim searchTBx As TextBox = CType(cp.FindControl("sear chTB"), TextBox)
search = searchTBx.Text
End If
Parent Master:
<!-- Content Body Holder -->
<div style="border-width: 1em; border-color: #000;">
<asp:ContentPlaceHolder id="defaultBodyCPH" runat="server"></asp:Conte
</div>
Child Master:
<asp:Content ID="Content2" ContentPlaceHolderID="defa
<!--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/searchI
<asp:textboxwatermarkexten
</div>
</asp:Content>
Codebehind:
'This code works in conjunction with the Event handler in the ListViewMasterPage VB code
Dim masterPage As MasterPages_ListViewMaster
Dim cp As ContentPlaceHolder = CType(Me.Master.Master.Fin
'Dim db As ClientInfoDataContext = New ClientInfoDataContext
Dim search As String
If Not IsNothing(masterPage) Then
Dim searchTBx As TextBox = CType(cp.FindControl("sear
search = searchTBx.Text
End If
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.