Does not Work - Literal1 control in MasterPage.Master
-
Hi Guys, I have a problem here and I don't know if why does the Literal1 control in MasterPage.Master will not change the value. What I am currently doing is to call the Litera1 control of MasterPage.Master from the content page. And when I tried this one I got an error that says - Object reference not set to an instance of an object". I really don't know why does the calling Literal1 control when call at runtime and change the value of it, it just didn't reflect the changes, and I even got an error that says - "Object reference not set to an instance of an object". I am stuck with this portion. I pasted below here a sample of asp.net/C# source codes. Actually the error is pointing here ltlBodyTitle.Text = "<b>hello</b>"; MasterPage.Master: <%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <asp:ContentPlaceHolder id="head" runat="server"> </asp:ContentPlaceHolder> </head> <body> <form id="form1" runat="server"> <div> <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server"> <asp:Literal ID="Literal1" runat="server"></asp:Literal> </asp:ContentPlaceHolder> </div> </form> </body> </html> ---------------------- Content Page should change the value of Literal1.text which was placed in the MasterPage.page. But it won't. Below is the finding of Literal1.text and suppose should change new value. Test.ASP.aspx.cs source codes. using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using Syst
-
Hi Guys, I have a problem here and I don't know if why does the Literal1 control in MasterPage.Master will not change the value. What I am currently doing is to call the Litera1 control of MasterPage.Master from the content page. And when I tried this one I got an error that says - Object reference not set to an instance of an object". I really don't know why does the calling Literal1 control when call at runtime and change the value of it, it just didn't reflect the changes, and I even got an error that says - "Object reference not set to an instance of an object". I am stuck with this portion. I pasted below here a sample of asp.net/C# source codes. Actually the error is pointing here ltlBodyTitle.Text = "<b>hello</b>"; MasterPage.Master: <%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <asp:ContentPlaceHolder id="head" runat="server"> </asp:ContentPlaceHolder> </head> <body> <form id="form1" runat="server"> <div> <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server"> <asp:Literal ID="Literal1" runat="server"></asp:Literal> </asp:ContentPlaceHolder> </div> </form> </body> </html> ---------------------- Content Page should change the value of Literal1.text which was placed in the MasterPage.page. But it won't. Below is the finding of Literal1.text and suppose should change new value. Test.ASP.aspx.cs source codes. using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using Syst
hifiger2004 wrote:
Literal ltlBodyTitle = (Literal)Master.FindControl("Literall1"); ltlBodyTitle.Text = "<b>hello</b>"; // Error here in this line
What is the error ? I assume a null reference ? We have an ASP.NET forum, you know. This sort of code is ugly as sin. You should try to never do this. Instead, create a base page that returns a strongly typed version of your master page, and use it's methods to set things like this.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
hifiger2004 wrote:
Literal ltlBodyTitle = (Literal)Master.FindControl("Literall1"); ltlBodyTitle.Text = "<b>hello</b>"; // Error here in this line
What is the error ? I assume a null reference ? We have an ASP.NET forum, you know. This sort of code is ugly as sin. You should try to never do this. Instead, create a base page that returns a strongly typed version of your master page, and use it's methods to set things like this.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
Yes, it works using basepage. Thanks
hifiger2004