Condividi tramite


MasterPage.Master Proprietà

Definizione

Ottiene la pagina master padre del master corrente in scenari di pagine master annidate.

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

Valore della proprietà

Pagina master padre della pagina master corrente; in caso contrario, null, se la pagina master corrente non ha un elemento padre.

Attributi

Esempio

Questa sezione contiene tre esempi di codice. Il primo esempio di codice illustra come creare una pagina. master nidificata Il secondo esempio di codice illustra come fare riferimento alla pagina master creata nel primo esempio di codice. Il terzo esempio di codice illustra come usare una pagina di contenuto per fare riferimento alla pagina master creata nel secondo esempio di codice.

Nell'esempio di codice seguente viene illustrato come creare una pagina master nidificata e rappresenta la pagina master padre denominata 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>

Nell'esempio di codice seguente viene illustrato come usare una pagina master nidificata denominata ChildMasterPage_1 che fa riferimento alla pagina master creata nell'esempio di codice precedente.

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

Nell'esempio di codice seguente viene illustrato come usare una pagina di contenuto denominata ContentPage che fa riferimento all'oggetto ChildMasterPage_1 creato nell'esempio di codice precedente.

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

Commenti

La Master proprietà è di sola lettura, perché non è possibile compilare gerarchie di pagine master in fase di esecuzione.

Si applica a

Vedi anche