O.O O.O - 4 months ago 45
ASP.NET (C#) Question

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?

Answer

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>