22

Having a "duh" moment trying to implement a new content page

Here's the structure

Master Page
---- Nested Master Page
-------- Nested Master's Content Page

Mark up:

Master Page

<asp:ContentPlaceHolder ID="bodyContent" runat="server">
</asp:ContentPlaceHolder>

Nested Master Page

MasterPageFile="~/Views/Shared/Administrator.Master"
<asp:Content ID="Content2" CotentPlaceHolderID="bodyContent" runat="server">
 </asp:Content>

Nested Master's Content Page

MasterPageFile="~/Views/Intervention/InterventionMaster.master"
<asp:Content runat="server" ID="myContent" ContentPlaceHolderID="Content2">
 </asp:Content>

Receive error:

Cannot find ContentPlaceHolder 'Content2' in the master page '/Views/Intervention/InterventionMaster.master', verify content control's ContentPlaceHolderID attribute in the content page.

What could I be doing wrong?

O.O
  • 11,077
  • 18
  • 94
  • 182
  • is it possible that your content-page is referring to the outer-most master page instead of the nested one? – n8wrl Feb 09 '12 at 18:13
  • First off, you're nesting master pages. What does this buy you? Most likely you've got the wrong master definition at the top of your aspx page. Can you show us the MasterPageFile directive of the Nested Content page? – Joel Etherton Feb 09 '12 at 18:14
  • @n8wrl - Not sure how, since I have this in the content page: MasterPageFile="~/Views/Intervention/InterventionMaster.master – O.O Feb 09 '12 at 18:14
  • @subt13: According to the documentation the nested content page needs to reference the nested master rather than the parent. I'd look at this for the first point of debugging. – Joel Etherton Feb 09 '12 at 18:15
  • @JoelEtherton - nested master pages saves me from writing a lot of redundant markup – O.O Feb 09 '12 at 18:21

4 Answers4

26

You don't have ContentPlaceHolder with ID = "Content2". You have only content with such ID. Put another placeholder inside of content with ID="Content2" and then connect with the page content.

Master Page

<asp:ContentPlaceHolder ID="bodyContent" runat="server">
</asp:ContentPlaceHolder>

Nested Master Page

<asp:Content ID="Content2" ContentPlaceHolderID="bodyContent" runat="server">
    <asp:ContentPlaceHolder ID="nestedContent" runat="server">
    </asp:ContentPlaceHolder>
 </asp:Content>

Nested Master's Content Page

<asp:Content runat="server" ID="myContent" ContentPlaceHolderID="nestedContent">
 </asp:Content>
giraffesyo
  • 4,860
  • 1
  • 29
  • 39
Samich
  • 29,157
  • 6
  • 68
  • 77
  • Hello there is a syntax error in the nested master page section: CotentPlaceHolderID should be ContentPlaceHolderID – Mike Z Aug 03 '16 at 17:29
2

A dirty-quick solution would be to bypass the Nested Master Page from the Nested Master's Content Page

protected void Page_PreInit(object sender, EventArgs e)
        {
            Master.MasterPageFile = "~/Whatever.Master";
        }
rpax
  • 4,468
  • 7
  • 33
  • 57
0

Use ID="MainContent"

<asp:Content ID="Content2" ContentPlaceHolder ID="MainContent" runat="server"></asp:Content>
Codeone
  • 1,173
  • 2
  • 15
  • 40
0

Codeone was close, try using

<asp:Content ContentPlaceHolderID="MainContent" runat="server">
bmich72
  • 640
  • 5
  • 6