Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve Cannot find ContentPlaceHolder error?

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?

like image 785
O.O Avatar asked Feb 09 '12 18:02

O.O


2 Answers

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>
like image 55
Samich Avatar answered Nov 09 '22 01:11

Samich


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";
        }
like image 43
rpax Avatar answered Nov 09 '22 02:11

rpax