Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Trying to access MasterPage label from Child Codebehind
Message
From
11/05/2021 13:57:16
 
 
To
All
General information
Forum:
ASP.NET
Category:
Web forms
Title:
Trying to access MasterPage label from Child Codebehind
Miscellaneous
Thread ID:
01680311
Message ID:
01680311
Views:
35
Hi all

Got a web application that has a Master Page with a label for the Child Page (lblTitle) on it. I'd like to set the lblTitle text from the child pages.

Master ASP
      <asp:ContentPlaceHolder ID="MainContent" runat="server">
        <div>
          <br />
          <asp:Label ID="lblTitle" runat="server" Text="" Font-Bold="true" Font-Size="X-Large" ></asp:Label>
          <br />
        </div>
      </asp:ContentPlaceHolder>
Master code behind
  public string SetMasterTitle
  {
    get { return this.lblTitle.Text; }
    set { this.lblTitle.Text = value; }
  }
Chile Code behind (trying to set lblTitle.text)
      MasterPage master = this.Master;
      if(master != null)
        this.Master.SetMasterTitle = "Transfer - No Offense Report";
I keep getting the error
: 'Object reference not set to an instance of an object.'

lblTitle was null.

So, where am I going wrong?
"You don't manage people. You manage things - people you lead" Adm. Grace Hopper
Pflugerville, between a Rock and a Weird Place
Next
Reply
Map
View

Click here to load this message in the networking platform