MasterPage.MasterPageFile プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > MasterPage.MasterPageFile プロパティの意味・解説 

MasterPage.MasterPageFile プロパティ

メモ : このプロパティは、.NET Framework version 2.0 で新しく追加されたものです。

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

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)
構文構文

Dim instance As MasterPage
Dim value As String

value = instance.MasterPageFile

instance.MasterPageFile = value
public string MasterPageFile { get;
 set; }
public:
property String^ MasterPageFile {
    String^ get ();
    void set (String^ value);
}
/** @property */
public String get_MasterPageFile ()

/** @property */
public void set_MasterPageFile (String value)
public function get MasterPageFile
 () : String

public function set MasterPageFile
 (value : String)

プロパティ値
現在のマスタ ページの親であるマスタ ページの名前。現在のマスタ ページに親が存在しない場合は null 参照 (Visual Basic では Nothing)。

例外例外
例外の種類条件

InvalidOperationException

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>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

MasterPage.MasterPageFile プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



MasterPage.MasterPageFile プロパティのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS