简体   繁体   English

asp.net中的嵌套母版页

[英]Nested Master Page in asp.net

In a nested Master page, the child master pages define the attribute MasterPageFile set in the @ Master declaration. 在嵌套的母版页中,子母版页定义@ Master声明中设置的属性MasterPageFile。 This attribute points to the parent master page. 此属性指向父母版页。

Is it True or False ? 是对还是错?

Yes, It's True. 对,是真的。

The Parent Master Page: 家长主页面:

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

The Child Master Page: 儿童母版页:

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

This is a child file that references the child master page: 这是一个引用子母版页的子文件:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM