How to resolve Cannot find ContentPlaceHolder error?
Asked Answered
D

4

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?

Devisable answered 9/2, 2012 at 18:10 Comment(5)
is it possible that your content-page is referring to the outer-most master page instead of the nested one?Atrabilious
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?Doityourself
@Atrabilious - Not sure how, since I have this in the content page: MasterPageFile="~/Views/Intervention/InterventionMaster.masterDevisable
@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.Doityourself
@JoelEtherton - nested master pages saves me from writing a lot of redundant markupDevisable
M
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>
Mangan answered 9/2, 2012 at 18:14 Comment(1)
Hello there is a syntax error in the nested master page section: CotentPlaceHolderID should be ContentPlaceHolderIDLiquidity
J
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";
        }
Jagged answered 10/3, 2014 at 9:28 Comment(0)
F
0

Use ID="MainContent"

<asp:Content ID="Content2" ContentPlaceHolder ID="MainContent" runat="server"></asp:Content>
Frivol answered 13/6, 2016 at 8:49 Comment(0)
M
0

Codeone was close, try using

<asp:Content ContentPlaceHolderID="MainContent" runat="server">
Micromillimeter answered 21/8, 2021 at 14:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.