0

I need to get the Master page Label Control but I am getting only null.

Master Page:

<div class="content">
                    <div class="container">

                        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
                             <asp:TextBox ID="txtUName" runat="server" Text="Raji"></asp:TextBox>
                            <asp:Label runat="server" ID="Label1" Style="padding: 10px; font-size: medium; font-family: Calibri" align="left" Text="Save"/>
                        </asp:ContentPlaceHolder>
                    </div>
                </div>

Child Page Code behind:

 public static void ClientMessage(Page p, string message)
 {
  Label _lblClientMessage_ = p.Master.FindControl("Label1") as Label;     
 }

Kindly assist me to get this master page Label control in child page.

dinesh.k
  • 187
  • 1
  • 6
  • 22
  • You should think if it's a good idea to hardwire this page with the master-page. Also, if you really want it you should provide a property(for example `ClientMessage`) in the master which gets and sets the text. Then you dont need to find this label with a specific ID but you just need to cast the `Master` property to the real type: `((TypeOfMaster)p.Master).ClientMessage = message;` – Tim Schmelter Jun 12 '18 at 10:28
  • Find control doesn't always dive down as deep as you might think. You might need to start at a "lower" point in the HTML (lower than master) – baileyrt Jun 12 '18 at 10:29
  • >firstly // Get a reference to the master page MasterPage ctl00 = FindControl("ctl00") as MasterPage; // Get a reference to the ContentPlaceHolder ContentPlaceHolder MainContent = ctl00.FindControl("MainContent") as ContentPlaceHolder; // Reference the Label controls Label ResultsLabel = MainContent.FindControl("Label1") as Label; – ArunPratap Jun 12 '18 at 10:29

0 Answers0