asp.net 3.5 nested master page problem

Joined
Jun 21, 2010
Messages
1
Reaction score
0
Hi, I have encountered an issue that must be common with Nested Master Pages. The problem I am having is when my content page uses a child master page, it calls the Master Page's Page_Load. Inside the Page_Load it is modifying a Literal that will not exist on the content page and throws an error. I understand why this happens, but my question is what is the best way to avoid this?

Site.master
Code:
        <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
            <asp:Literal ID="Literal1" runat="server"></asp:Literal>
        </asp:ContentPlaceHolder>
        <asp:ContentPlaceHolder id="ContentPlaceHolder2" runat="server">
            <asp:Literal ID="Literal2" runat="server"></asp:Literal>
        </asp:ContentPlaceHolder>

Site.master.cs
Code:
public partial class Site : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {

        Literal1.Text = "something";   // Works fine
        Literal2.Text = "something";   // Error occurs here.  
    }
}

Child.master
Code:
        <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">

        <!-- No Literal Control ->
        </asp:Content>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top