ContentPlaceHolder Web サーバー コントロールの宣言構文
更新 : 2007 年 11 月
ASP.NET マスタ ページ内にコンテンツ用の領域を作成します。
<asp: ContentPlaceHolder
EnableViewState="True|False"
ID="string"
OnDataBinding="DataBinding event handler"
OnDisposed="Disposed event handler"
OnInit="Init event handler"
OnLoad="Load event handler"
OnPreRender="PreRender event handler"
OnUnload="Unload event handler"
runat="server"
Visible="True|False"
>
<!-- child controls -->
</asp:ContentPlaceHolder>
解説
ContentPlaceHolder コントロールは、マスタ ページ内のコンテンツ用の相対領域を定義し、コンテンツ ページにある関連付けられた Content コントロールから、すべてのテキスト、マークアップ、およびサーバー コントロールを描画します。
Content コントロールは、その ContentPlaceHolderID プロパティによって ContentPlaceHolder に関連付けられます。ContentPlaceHolderID プロパティを、マスタ ページ内の関連する ContentPlaceHolder コントロールの ID プロパティの値に設定します。マスタ ページ内では、1 つ以上の ContentPlaceHolder を宣言できます。マスタ ページの詳細については、「ASP.NET マスター ページ」を参照してください。
使用例
ContentPlaceHolder コントロールを使用して、マスタ ページのコンテンツ領域を定義する方法を次のコード例に示します。この Web ページはマスタ ページで、ContentPlaceHolder コントロールを使用してコンテンツ領域を定義しています。コンテンツ ページは、@ Page ディレクティブの MasterPageFile 属性を設定し、Content コントロールを定義することによって、このマスタ ページを参照しています。
<%@ Master Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>MasterPage Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server" />
</div>
</form>
</body>
</html>
<%@ Master Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>MasterPage Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server" />
</div>
</form>
</body>
</html>