MasterPage.MasterPageFile Proprietà

Definizione

Ottiene o imposta il nome della pagina master contenente il contenuto corrente.

public:
 property System::String ^ MasterPageFile { System::String ^ get(); void set(System::String ^ value); };
public string MasterPageFile { get; set; }
member this.MasterPageFile : string with get, set
Public Property MasterPageFile As String

Valore della proprietà

Nome della pagina master padre della pagina master corrente; in caso contrario, null, se la pagina master corrente non ha una pagina master padre.

Eccezioni

La proprietà MasterPageFile può essere impostata esclusivamente nell'evento PreInit o prima di esso.

Esempio

Questa sezione contiene tre esempi di codice. Il primo esempio di codice illustra come creare una pagina master annidata 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 annidata 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 annidata 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>  

Si applica a

Vedi anche