MasterPage.MasterPageFile Propiedad

Definición

Obtiene o establece el nombre de la página maestra que tiene el contenido actual.

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

Valor de propiedad

Nombre de la página maestra que es el elemento principal de la página maestra actual; en caso contrario, null, si la página maestra actual no tiene elemento principal.

Excepciones

La propiedad MasterPageFile sólo se puede establecer en el evento PreInit, o antes de que se produzca.

Ejemplos

Esta sección contiene tres ejemplos de código. En el primer ejemplo de código se muestra cómo crear una página. maestra anidada. En el segundo ejemplo de código se muestra cómo hacer referencia a la página maestra que se creó en el primer ejemplo de código. En el tercer ejemplo de código se muestra cómo usar una página de contenido para hacer referencia a la página maestra que se creó en el segundo ejemplo de código.

En el ejemplo de código siguiente se muestra cómo crear una página maestra anidada y representa la página maestra primaria denominada 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>  

En el ejemplo de código siguiente se muestra cómo usar una página maestra anidada denominada ChildMasterPage_1 que hace referencia a la página maestra que se creó en el ejemplo de código anterior.

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

En el ejemplo de código siguiente se muestra cómo usar una página de contenido denominada ContentPage que hace referencia al ChildMasterPage_1 objeto que se creó en el ejemplo de código anterior.

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

Se aplica a

Consulte también