System.Web.HttpException: Content controls have to be top-level controls in a content page or a nest

Posted by SheoNarayan under Error and Solution on 2/18/2011 | Points: 10 | Views : 14550 | Status : [Administrator] | Replies : 0

I was getting this error when trying with the Nested Master page.

System.Web.HttpException: Content controls have to be top-level controls in a content page or a nested master page that references a master page.

You need to focus following while dealing with this issue

1. By default Visual Studio doesn't not create ContentPlaceHolder control in the Child Master page, for example look at the below code

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<p>Written in child master page </p>
<asp:ContentPlaceHolder id="ChildMasterContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>

</asp:Content>


You will need to make sure that you are keeping the ContentPlaceHolder control inside the asp:Content control.

2. Any content (plain text/html control/asp.net control) either in the Child master page or Content page must be inside the asp:Content control.

3. You can keep any content in the Maste Master page under body tag.

4. The hierarchy of Page_Load method fires like this
--------------Content page page_load
-------------------Child master page page_load
-------------------------Master master page_load

Hope this helps.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com



Responses

(No response found.)

Login to post response