C# 内容控件必须是内容页或引用母版页的嵌套母版页中的顶级控件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13745449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Content controls have to be top-level controls in a content page or a nested master page that references a master page
提问by Anyname Donotcare
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
内容控件必须是内容页或引用母版页的嵌套母版页中的顶级控件
采纳答案by erik_nw
The HTML-code in your nested masterpage must be wrapped with an asp:content-tag with a contentplaceholderid from the "master" masterpage.
嵌套母版页中的 HTML 代码必须用 asp:content-tag 包裹,其中包含来自“母版”母版页的 contentplaceholderid。
回答by Dunc
Just to demonstrate Erik's point:
只是为了证明 Erik 的观点:
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>

