2016-11-14 42 views
0

在嵌套母版页中,子母版页面定义在@ Master声明中设置的属性MasterPageFile。该属性指向父母母版页。asp.net中的嵌套主页面

是对还是错?

+0

是,检查嵌套ASP.NET母版页:https://msdn.microsoft.com/en-us/library/x2b3ktt7.aspx – Damith

回答

2

是的,这是真的。

家长母版页:

<% @ Master Language="C#" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 
    1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server"> 
    <title>Untitled Page</title> 
</head> 
<body> 
<form id="Form1" runat="server"> 
<div> 
<h1>Parent Master</h1> 
<p style="font:color=red">This is parent master content.</p> 
<asp:ContentPlaceHolder ID="MainContent" runat="server" /> 
</div> 
</form> 
</body> 
</html> 

子母版页:

<%@ Master Language="C#" MasterPageFile="~/Parent.master"%> 
<asp:Content id="Content1" ContentPlaceholderID="MainContent" runat="server"> 
    <asp:panel runat="server" id="panelMain" backcolor="lightyellow"> 
    <h2>Child master</h2> 
     <asp:panel runat="server" id="panel1" backcolor="lightblue"> 
     <p>This is child master content.</p> 
     <asp:ContentPlaceHolder ID="ChildContent1" runat="server" /> 
     </asp:panel> 
     <asp:panel runat="server" id="panel2" backcolor="pink"> 
     <p>This is child master content.</p> 
     <asp:ContentPlaceHolder ID="ChildContent2" runat="server" /> 
     </asp:panel> 
     <br /> 
    </asp:panel> 
</asp:Content> 

这是引用子母版页的子文件:

<%@ Page Language="C#" MasterPageFile="~/Child.master"%> 
<asp:Content id="Content1" ContentPlaceholderID="ChildContent1" runat="server"> 
    <asp:Label runat="server" id="Label1" 
     text="Child label1" font-bold="true" /> 
    <br /> 
</asp:Content> 
<asp:Content id="Content2" ContentPlaceholderID="ChildContent2" runat="server"> 
    <asp:Label runat="server" id="Label2" 
     text="Child label2" font-bold="true"/> 
</asp:Content>