MasterPage.MasterPageFile Propiedad

Definición

Obtiene o establece el nombre de la página maestra que contiene 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 primario de la página maestra actual; de lo contrario, nullsi la página maestra actual no tiene ningún elemento primario.

Excepciones

La MasterPageFile propiedad solo se puede establecer en o antes del PreInit evento .

Ejemplos

Esta sección contiene tres ejemplos de código. El primer ejemplo de código muestra cómo crear una página. maestra anidada El segundo ejemplo de código 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 principal 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 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