Nested Master pages don't work

S

SammyBar

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
 
M

miher

SammyBar said:
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
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top