Nested Master pages don't work

Discussion in 'ASP .Net Web Controls' started by SammyBar, Apr 6, 2009.

  1. SammyBar

    SammyBar Guest

    I'm trying to get to work the simplest example on nested master pages. But
    I'm receiving the error: "Content controls have to be top-level controls in
    a content page or a nested master page that references a master page. "

    My pages are the next:

    Parent.Master:
    <%@ Master Language="C#" AutoEventWireup="true"
    CodeBehind="Parent.master.cs"
    Inherits="mx.com.Matusa.MatusaWeb2.test.Parent" %>

    <!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>Untitled Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:ContentPlaceHolder ID="MasterContentPlaceHolder"
    runat="server">
    </asp:ContentPlaceHolder>
    </div>
    </form>
    </body>
    </html>
    --------------------------------------------------------------
    Child.Master
    <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Child.master.cs"
    Inherits="mx.com.Matusa.MatusaWeb2.test.Child"
    MasterPageFile="~/test/Parent.Master" %>

    <asp:Content ContentPlaceHolderID="MasterContentPlaceHolder">
    <asp:ContentPlaceHolder ID="ChildContentPlaceHolder" runat="server">
    </asp:ContentPlaceHolder>
    </asp:Content>
    ----------------------------------------------------------------
    WebForm2.aspx
    <%@ Page Language="C#" MasterPageFile="~/test/Child.Master"
    AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs"
    Inherits="mx.com.Matusa.MatusaWeb2.test.WebForm2" Title="Untitled Page" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="ChildContentPlaceHolder"
    runat="server">
    <p>qwerty</p>
    </asp:Content>

    It looks like ASP.NET does not like the embedding of ContentPlaceHolder
    inside Content, but it is the way the nesting works in all examples I have
    been looking. What is wrong?

    Thanks in advance
    Sammy
     
    SammyBar, Apr 6, 2009
    #1
    1. Advertising

  2. SammyBar

    miher Guest

    "SammyBar" <> wrote in message
    news:#...
    > I'm trying to get to work the simplest example on nested master pages. But
    > I'm receiving the error: "Content controls have to be top-level controls
    > in a content page or a nested master page that references a master page. "
    >
    > My pages are the next:
    >
    > Parent.Master:
    > <%@ Master Language="C#" AutoEventWireup="true"
    > CodeBehind="Parent.master.cs"
    > Inherits="mx.com.Matusa.MatusaWeb2.test.Parent" %>
    >
    > <!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>Untitled Page</title>
    > </head>
    > <body>
    > <form id="form1" runat="server">
    > <div>
    > <asp:ContentPlaceHolder ID="MasterContentPlaceHolder"
    > runat="server">
    > </asp:ContentPlaceHolder>
    > </div>
    > </form>
    > </body>
    > </html>
    > --------------------------------------------------------------
    > Child.Master
    > <%@ Master Language="C#" AutoEventWireup="true"
    > CodeBehind="Child.master.cs"
    > Inherits="mx.com.Matusa.MatusaWeb2.test.Child"
    > MasterPageFile="~/test/Parent.Master" %>
    >
    > <asp:Content ContentPlaceHolderID="MasterContentPlaceHolder">
    > <asp:ContentPlaceHolder ID="ChildContentPlaceHolder"
    > runat="server">
    > </asp:ContentPlaceHolder>
    > </asp:Content>
    > ----------------------------------------------------------------
    > WebForm2.aspx
    > <%@ Page Language="C#" MasterPageFile="~/test/Child.Master"
    > AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs"
    > Inherits="mx.com.Matusa.MatusaWeb2.test.WebForm2" Title="Untitled Page" %>
    > <asp:Content ID="Content1" ContentPlaceHolderID="ChildContentPlaceHolder"
    > runat="server">
    > <p>qwerty</p>
    > </asp:Content>
    >
    > It looks like ASP.NET does not like the embedding of ContentPlaceHolder
    > inside Content, but it is the way the nesting works in all examples I have
    > been looking. What is wrong?
    >
    > Thanks in advance
    > Sammy



    Hi,
    Apply runat="server" to Your child masters Content tag.

    Hope You find this useful.
    -Zsolt
     
    miher, Apr 7, 2009
    #2
    1. Advertising

  3. SammyBar

    SammyBar Guest

    > Apply runat="server" to Your child masters Content tag.
    >
    > Hope You find this useful.
    > -Zsolt

    Yes!!!!

    Thanks for your time
    Sammy
     
    SammyBar, Apr 7, 2009
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brandon

    Master Pages Don't Work

    Brandon, Nov 11, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    5,816
    ProgTalk
    Dec 4, 2007
  2. Doug McCann
    Replies:
    1
    Views:
    1,137
    William Brogden
    Aug 5, 2004
  3. Replies:
    1
    Views:
    3,280
    PeterKellner
    May 16, 2006
  4. katmagic
    Replies:
    0
    Views:
    1,311
    katmagic
    Dec 26, 2008
  5. SammyBar

    Nested Master pages don't work

    SammyBar, Apr 6, 2009, in forum: ASP .Net
    Replies:
    2
    Views:
    2,286
    SammyBar
    Apr 7, 2009
Loading...

Share This Page