MasterPage.Master 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在巢狀主版頁面案例中,取得目前主版頁面的父主版頁面。
public:
property System::Web::UI::MasterPage ^ Master { System::Web::UI::MasterPage ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Web.UI.MasterPage Master { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Master : System.Web.UI.MasterPage
Public ReadOnly Property Master As MasterPage
屬性值
目前主版頁面的父主版頁面,如果目前的主版頁面沒有父代,則為 null
。
- 屬性
範例
本節包含三個程式碼範例。 第一個程式碼範例示範如何建立嵌套主版頁面 .
,第二個程式碼範例示範如何參考第一個程式碼範例中所建立的主版頁面。 第三個程式碼範例示範如何使用內容頁面來參考第二個程式碼範例中所建立的主版頁面。
下列程式碼範例示範如何建立嵌套主版頁面,並代表名為的父主版頁面 ParentMasterPage_1
。
<%@ Master Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html >
<head runat="server">
<title>Nested Master Page Example</title>
</head>
<body>
<form id="form1" runat="server">
<h1>This is content in the parent master page.</h1>
<div>
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
</div>
</form>
</body>
</html>
<%@ Master Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html >
<head runat="server">
<title>Nested Master Page Example</title>
</head>
<body>
<form id="form1" runat="server">
<h1>This is content in the parent master page.</h1>
<div>
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
</div>
</form>
</body>
</html>
下列程式碼範例示範如何使用名為的嵌套主版頁面,該頁面會 ChildMasterPage_1
參考先前程式碼範例中所建立的主版頁面。
<%@ Master Language="C#" MasterPageFile="~/ParentMasterPage_1cs.master" %>
<asp:Content Runat="Server" ContentPlaceHolderID="ContentPlaceHolder1">
<h2>This is the content of a nested Master Page.</h2>
<div>
<asp:contentplaceholder id="ContentPlaceHolder2" runat="server">
</asp:contentplaceholder>
</div>
</asp:Content>
<%@ Master Language="VB" MasterPageFile="~/ParentMasterPage_1vb.master" %>
<asp:Content Runat="Server" ContentPlaceHolderID="ContentPlaceHolder1">
<h2>This is the content of a nested Master Page.</h2>
<div>
<asp:contentplaceholder id="ContentPlaceHolder2" runat="server">
</asp:contentplaceholder>
</div>
</asp:Content>
下列程式碼範例示範如何使用名為的內容頁面 ContentPage
,該頁面會參考 ChildMasterPage_1
先前程式碼範例中所建立的。
<%@ Page Language="C#" MasterPageFile="~/ChildMasterPage_1cs.master" Title="Untitled Page"%>
<asp:content runat="server" contentplaceholderid="ContentPlaceHolder2">
This is the content of a Content control.
</asp:content>
<%@ Page Language="VB" MasterPageFile="~/ChildMasterPage_1vb.master" Title="Untitled Page"%>
<asp:content runat="server" contentplaceholderid="ContentPlaceHolder2">
This is the content of a Content control.
</asp:content>
備註
Master屬性是唯讀的,因為主版頁面階層無法在執行時間建立。