R – Filling in parent master page from child

asp.netmaster-pages

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>

Best Answer

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>