MasterPage.MasterPageFile プロパティ

定義

現在のコンテンツが格納されているマスター ページの名前を取得または設定します。

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

プロパティ値

現在のマスター ページの親であるマスター ページの名前。現在のマスター ページに親が存在しない場合は null

例外

MasterPageFile プロパティを設定できるのは、PreInit イベントの中か前だけです。

このセクションには、3 つのコード例が含まれています。 最初のコード例では、入れ子になったマスター ページ. を作成する方法を示します。2 番目のコード例では、最初のコード例で作成されたマスター ページを参照する方法を示します。 3 番目のコード例では、コンテンツ ページを使用して、2 番目のコード例で作成されたマスター ページを参照する方法を示します。

次のコード例では、入れ子になったマスター ページを作成し、 という名前 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>  

次のコード例では、前のコード例で作成したマスター ページを参照する という名前 ChildMasterPage_1 の入れ子になったマスター ページを使用する方法を示します。

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

次のコード例では、前のコード例で作成した をChildMasterPage_1参照する という名前ContentPageのコンテンツ ページを使用する方法を示します。

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

適用対象

こちらもご覧ください