Content Web サーバー コントロールの宣言構文
更新 : 2007 年 11 月
マスタ ページの ContentPlaceHolder コントロールに描画されるテキスト、マークアップ、およびその他のサーバー コントロールを格納するサーバー コントロールを作成します。
<asp:Content
ContentPlaceHolderID="string"
EnableViewState="True|False"
ID="string"
runat="server">
Visible="True|False"
<!-- child controls -->
</asp:Content>
解説
Content コントロールは、コンテンツ ページのコンテンツおよびコントロールのコンテナです。Content コントロールが使用されるのは、対応する ContentPlaceHolder コントロールを定義するマスタ ページが使用される場合のみです。Content コントロールは、スタンドアロンのコントロールではありません。マスタ ページの詳細については、「ASP.NET マスター ページ」を参照してください。
使用例
このセクションでは、2 つのコード例を紹介します。最初のコード例では、Content コントロールを使用して、マスタ ページのコンテンツを定義する方法を示します。2 番目のコード例では、最初のコード例で取り上げたマスタ ページのコンテンツ ページを使用する方法を示します。
Content コントロールを使用して、マスタ ページのコンテンツを定義する方法を次のコード例に示します。最初の Web ページはマスタ ページで、ContentPlaceHolder コントロールを使用してコンテンツ領域を定義しています。
<%@ 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>
前のコード例で取り上げたマスタ ページのコンテンツ ページを使用する方法を次のコード例に示します。Content コントロールのテンプレートで定義されたテキスト、マークアップ、およびサーバー コントロールが、マスタ ページ上の ContentPlaceHolder に描画されます。
<%@ Page Language="C#" MasterPageFile="~/MasterPageSample_1cs.master" Title="Content Page"%>
<asp:content
runat="server"
contentplaceholderid="ContentPlaceHolder1" >Hello, Master Pages!</asp:content>
<%@ Page Language="VB" MasterPageFile="~/MasterPageSample_1vb.master" Title="Content Page"%>
<asp:content
runat="server"
contentplaceholderid="ContentPlaceHolder1" >Hello, Master Pages!</asp:content>