Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Does not Work - Literal1 control in MasterPage.Master

Does not Work - Literal1 control in MasterPage.Master

Scheduled Pinned Locked Moved Web Development
csharphelphtmlasp-netlinq
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hifiger2004
    wrote on last edited by
    #1

    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

    C 1 Reply Last reply
    0
    • H hifiger2004

      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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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.

      H 1 Reply Last reply
      0
      • C Christian Graus

        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.

        H Offline
        H Offline
        hifiger2004
        wrote on last edited by
        #3

        Yes, it works using basepage. Thanks

        hifiger2004

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups