7

我想使用嵌套母版页,所以我创建了以下母版页:

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

我收到以下错误:

内容控件必须是内容页或引用母版页的嵌套母版页中的顶级控件

4

2 回答 2

11

嵌套母版页中的 HTML 代码必须使用 asp:content-tag 包装,该标签带有来自“母版”母版页的 contentplaceholderid。

于 2012-12-06T14:29:06.447 回答
5

只是为了证明 Erik 的观点:

父主页:

<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>
于 2013-12-17T09:43:36.880 回答