Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Trying to access MasterPage label from Child Codebehind
Message
 
 
À
11/05/2021 13:57:16
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires Web
Divers
Thread ID:
01680311
Message ID:
01680324
Vues:
24
>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?

Just a guess. I think you need to be USING ... Master Page in the Child page.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform