views:

486

answers:

2

I'd like to have a page that uses a child master page, fill in a content placeholder of the parent, but I cannot get it to work. Whenever I try I get the error "Cannot find ContentPlaceHolder 'customHead' in the master page '/templates/info.master', verify content control's ContentPlaceHolderID attribute in the content page."

I have a master page (/templates/main.master) defined like this:

<%@ Master Language="C#" %>
<head runat="server">
    <title>foo</title>
    <asp:contentplaceholder runat="server" id="customHead" />
</head>
<body>
    <div id="content">
     <asp:contentplaceholder runat="server" id="masterContent" />
    </div>

Then I have a child master (/templates/info.master) defined like this:

<%@ Master Language="C#" MasterPageFile="/templates/main.master" %>
<asp:content id="homeContent" contentPlaceHolderId="masterContent" Runat="server">
<div id="info-container">
    <div id="info-content">
     <asp:contentplaceholder runat="server" id="infoContent"/>
    </div>
</div>
</asp:content>

And finally my page defined like this:

<%@ Page Language="C#" MasterPageFile="/templates/info.master" %>
<asp:Content ID="head" ContentPlaceHolderID="customHead" runat="server">
    <!-- Custom header area -->
    <link rel="stylesheet" type="text/css" href="foo.css"/>
</asp:Content>
<asp:Content ID="content" ContentPlaceHolderID="childContent" runat="server">
    This is my child content
</asp:Content>
+1  A: 

Are you setting it using this.Page.Master ?

Chris Ballance
+2  A: 

You didn't define a "customeHead" in your child master page. If you want to expose the root master pages content area, you'll need to expose it in the child master page.

<%@ Master Language="C#" MasterPageFile="/templates/main.master" %>
<asp:contentplaceholder runat="server" id="customHead" />
<asp:content id="homeContent" contentPlaceHolderId="masterContent" Runat="server">
 <div id="info-container">
     <div id="info-content">
         <asp:contentplaceholder runat="server" id="infoContent"/>       
     </div>
 </div>
</asp:content>
Zachary
Adding the placeholder there just gives me this error:"Parser Error Message: Only Content controls are allowed directly in a content page that contains Content controls."
Jonathan Arkell
@Zachary, I think you've got it mostly right you just need a contentplaceholder control embedded within another content control on the info.master page:<asp:Content ContentPlaceHolderID="customHead" runat="server"><asp:ContentPlaceHolder runat="server" id="customHead" /></asp:Content>
Mxyzptlk
With Mxyzptlks addition, it worked like a charm. Thank you both!
Jonathan Arkell