Επεξεργασία

Κοινή χρήση μέσω


MasterPage.Master Property

Definition

Gets the parent master page of the current master in nested master pages scenarios.

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

Property Value

The master page that is the parent of the current master page; otherwise, null, if the current master page has no parent.

Attributes

Examples

This section contains three code examples. The first code example demonstrates how to create a nested master page. The second code example demonstrates how to reference the master page that was created in the first code example. The third code example demonstrates how to use a content page to reference the master page that was created in the second code example.

The following code example demonstrates how to create a nested master page and represents the parent master page named 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>  

The following code example demonstrates how to use a nested master page named ChildMasterPage_1 that references the master page that was created in the preceding code example.

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

The following code example demonstrates how to use a content page named ContentPage that references the ChildMasterPage_1 that was created in the preceding code example.

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

Remarks

The Master property is read-only, because master page hierarchies cannot be built at run time.

Applies to

See also