更新 : 2007 年 11 月
ASP.NET マスタ ページにコンテンツの領域を定義します。
名前空間 :
System.Web.UI.WebControls アセンブリ :
System.Web (System.Web.dll 内)
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class ContentPlaceHolder _
Inherits Control _
Implements INamingContainer
Dim instance As ContentPlaceHolder
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class ContentPlaceHolder : Control,
INamingContainer
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class ContentPlaceHolder : public Control,
INamingContainer
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal) */
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal) */
public class ContentPlaceHolder extends Control implements INamingContainer
public class ContentPlaceHolder extends Control implements INamingContainer
<asp:ContentPlaceHolder />
ContentPlaceHolder コントロールはマスタ ページにコンテンツの相対領域を定義し、コンテンツ ページ内にある関連付けられた Content コントロールからすべてのテキスト、マークアップ、およびサーバー コントロールを表示します。
Content コントロールはその ContentPlaceHolderID プロパティを使用して、ContentPlaceHolder に関連付けられます。ContentPlaceHolderID プロパティを、マスタ ページの関連付けられた ContentPlaceHolder コントロールの ID プロパティの値に設定します。マスタ ページには、1 つ以上の ContentPlaceHolder を宣言できます。
コンテンツ ページでは、マスタ ページの ContentPlaceHolder のコンテンツを提供できるのは 1 つの Content コントロールだけです。ただし、マスタ ページを使用するコンテンツ ページごとに、別々の Content コントロールを ContentPlaceHolder に関連付けることができます。たとえば、マスタ ページのページ タイトルに ContentPlaceHolder を定義できます。マスタ ページを使用するコンテンツ ページごとに、ページ タイトルのテキストおよびマークアップを提供する Content コントロールを追加できます。
メモ : |
|---|
XHtml に準拠するため、タイトルが定義されていない場合や見つからない場合は空のタイトル要素が作成されます。 |
ContentPlaceHolder コントロールのタグ内に置かれる既定のコンテンツを指定できますが、このコンテンツはコンテンツ ページに関連付けられた任意のコンテンツで置き換えられます。
マスタ ページおよびコンテンツ ページの詳細については、「ASP.NET マスター ページ」を参照してください。
ContentPlaceHolder コントロールを使用して、マスタ ページのコンテンツ領域を定義する方法のコード例を次に示します。最初の Web ページはマスタ ページで、ContentPlaceHolder コントロールを使用してコンテンツ領域を定義します。
<%@ 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>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 >
<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 に表示されます。
Class SampleMasterClass
Inherits System.Web.UI.MasterPage
Dim asitename As String
Public Property SiteName() As String
Get
Return asitename
End Get
Set(ByVal Value as String)
asitename = Value
End Set
End Property
End Class
public class SampleMasterClass : System.Web.UI.MasterPage {
private string sitename;
public string SiteName
{
get {return(sitename);}
set {sitename = value;}
}
}
System..::.Object
System.Web.UI..::.Control
System.Web.UI.WebControls..::.ContentPlaceHolder
この型のすべてのパブリック static (Visual Basic では Shared) メンバは、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
.NET Framework および .NET Compact Framework では、各プラットフォームのすべてのバージョンはサポートしていません。サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。
.NET Framework
サポート対象 : 3.5、3.0、2.0
参照
その他の技術情報