MasterPage.MasterPageFile Właściwość

Definicja

Pobiera lub ustawia nazwę strony wzorcowej zawierającej bieżącą zawartość.

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

Wartość właściwości

Nazwa strony wzorcowej, która jest elementem nadrzędnym bieżącej strony wzorcowej; w przeciwnym razie , nulljeśli bieżąca strona wzorcowa nie ma elementu nadrzędnego.

Wyjątki

Właściwość MasterPageFile można ustawić tylko w lub przed zdarzeniem PreInit .

Przykłady

Ta sekcja zawiera trzy przykłady kodu. Pierwszy przykład kodu przedstawia sposób tworzenia zagnieżdżonej strony. wzorcowej Drugi przykład kodu przedstawia sposób odwołowania się do strony wzorcowej utworzonej w pierwszym przykładzie kodu. W trzecim przykładzie kodu pokazano, jak używać strony zawartości do odwoływanie się do strony wzorcowej utworzonej w drugim przykładzie kodu.

Poniższy przykład kodu przedstawia sposób tworzenia zagnieżdżonej strony wzorcowej i reprezentuje nadrzędną stronę wzorcową o nazwie 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>  

W poniższym przykładzie kodu pokazano, jak używać zagnieżdżonej strony wzorcowej o nazwie ChildMasterPage_1 odwołującej się do strony wzorcowej utworzonej w poprzednim przykładzie kodu.

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

W poniższym przykładzie kodu pokazano, jak używać strony zawartości o nazwie ContentPage , która odwołuje ChildMasterPage_1 się do elementu utworzonego w poprzednim przykładzie kodu.

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

Dotyczy

Zobacz też