MasterPage.MasterPageFile プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
現在のコンテンツを含むマスター ページの名前を取得または設定します。
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>
次のコード例では、前のコード例で作成したContentPageを参照するChildMasterPage_1という名前のコンテンツ ページを使用する方法を示します。
<%@ 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>