web-dev-qa-db-ja.com

コンテンツコントロールは、コンテンツページまたはマスターページを参照するネストされたマスターページのトップレベルコントロールである必要があります

ネストされたマスターページを使用したいので、次のマスターページを作成します。

<%@ 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>

そして、そのマスターページを使用するために次のページを作成します。

<%@ 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>

次のエラーが発生します:

コンテンツコントロールは、コンテンツページまたはマスターページを参照するネストされたマスターページのトップレベルコントロールである必要があります

7

ネストされたマスターページのHTMLコードは、「マスター」マスターページのcontentplaceholderidを含むasp:content-tagでラップする必要があります。

9
erik_nw

エリックの主張を示すためだけに:

親マスターページ:

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

子マスターページ:

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

ページ:

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <!-- content -->
</asp:Content>
4
Dunc