Content controls have to be top-level controls in a content page or a nested master page that references a master page
Asked Answered
W

2

7

I want to use nested master page so i create the following master page :

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="test.master.cs" Inherits="DocumentFlowUI.test" MasterPageFile="~/MasterPage2.master" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
            <asp:Button ID="Button1" runat="server" Text="Button" />
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>

and i create the following page to use that master page :

<%@ Page Title="" Language="C#" MasterPageFile="~/test.Master" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="DocumentFlowUI.WebForm4" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</asp:Content>

I get the following error :

Content controls have to be top-level controls in a content page or a nested master page that references a master page

Weismannism answered 6/12, 2012 at 14:15 Comment(1)
Is it because your ContentPlaceHolder in the top level master page is inside your form which is runat server so it is not top level?Murine
S
11

The HTML-code in your nested masterpage must be wrapped with an asp:content-tag with a contentplaceholderid from the "master" masterpage.

Scopula answered 6/12, 2012 at 14:29 Comment(0)
A
5

Just to demonstrate Erik's point:

Parent masterpage:

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

Child masterpage:

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <asp:ContentPlaceHolder ID="head" runat="server" />
</asp:Content>

Page:

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <!-- content -->
</asp:Content>
Adrianople answered 17/12, 2013 at 9:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.