ContentPlaceHolder 类  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
为 ASP.NET 母版页中的内容定义区域。
public ref class ContentPlaceHolder : System::Web::UI::Controlpublic class ContentPlaceHolder : System.Web.UI.Controltype ContentPlaceHolder = class
    inherit Control
    interface INamingContainerPublic Class ContentPlaceHolder
Inherits Control- 继承
- 实现
示例
下面的代码示例演示如何 ContentPlaceHolder 使用 控件定义母版页的内容区域。 第一个网页是母版页,使用 ContentPlaceHolder 控件定义内容区域。
<%@ 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 母版页上的 。
public class SampleMasterClass : System.Web.UI.MasterPage {
     private string sitename;     
     public string SiteName
     {
        get {return(sitename);}
        set {sitename = value;}
     }
}
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
注解
控件 ContentPlaceHolder 定义母版页中内容的相对区域,并呈现内容页中找到的相关 Content 控件中的所有文本、标记和服务器控件。
控件Content使用 其 ContentPlaceHolderID 属性与 ContentPlaceHolder 关联。 将 ContentPlaceHolderID 属性设置为母版页中相关ContentPlaceHolder控件的 属性的值ID。 可以在母 ContentPlaceHolder 版页中声明多个。
在内容页中,只有一个 Content 控件可以在母版页中提供 的内容 ContentPlaceHolder 。 但是,在使用母版页的每个内容页中,可以具有与 ContentPlaceHolder关联的单独Content控件。 例如,可以为母版页中的页面标题定义 ContentPlaceHolder 。 对于使用母版页的每个内容页,可以添加一个 Content 控件,该控件为页面标题提供文本和标记。
注意
对于 XHTML 合规性,如果尚未定义或找不到游戏,则会创建一个空的 title 元素。
可以指定放置在控件标记中的 ContentPlaceHolder 默认内容,但此内容将替换为关联内容页中的任何内容。
有关母版页和内容页的详细信息,请参阅 DEL: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() | 初始化 ContentPlaceHolder 类的新实例。 | 
属性
| Adapter | 获取控件的浏览器特定适配器。(继承自 Control) | 
| AppRelativeTemplateSourceDirectory | 获取或设置包含该控件的 Page 或 UserControl 对象的应用程序相对虚拟目录。(继承自 Control) | 
| BindingContainer | 获取包含该控件的数据绑定的控件。(继承自 Control) | 
| ChildControlsCreated | 获取一个值,该值指示是否已创建服务器控件的子控件。(继承自 Control) | 
| ClientID | 获取由 ASP.NET 生成的 HTML 标记的控件 ID。(继承自 Control) | 
| ClientIDMode | 获取或设置用于生成 ClientID 属性值的算法。(继承自 Control) | 
| ClientIDSeparator | 获取一个字符值,该值表示 ClientID 属性中使用的分隔符字符。(继承自 Control) | 
| Context | 为当前 Web 请求获取与服务器控件关联的 HttpContext 对象。(继承自 Control) | 
| Controls | 获取 ControlCollection 对象,该对象表示 UI 层次结构中的指定服务器控件的子控件。(继承自 Control) | 
| DataItemContainer | 如果命名容器实现 IDataItemContainer,则获取对命名容器的引用。(继承自 Control) | 
| DataKeysContainer | 如果命名容器实现 IDataKeysControl,则获取对命名容器的引用。(继承自 Control) | 
| DesignMode | 获取一个值,该值指示是否正在使用设计图面上的一个控件。(继承自 Control) | 
| EnableTheming | 获取或设置一个值,该值指示主题是否应用于该控件。(继承自 Control) | 
| EnableViewState | 获取或设置一个值,该值指示服务器控件是否向发出请求的客户端保持自己的视图状态以及它所包含的任何子控件的视图状态。(继承自 Control) | 
| Events | 获取控件的事件处理程序委托列表。 此属性为只读。(继承自 Control) | 
| HasChildViewState | 获取一个值,该值指示当前服务器控件的子控件是否具有任何已保存的视图状态设置。(继承自 Control) | 
| ID | 获取或设置分配给服务器控件的编程标识符。(继承自 Control) | 
| IdSeparator | 获取用于分隔控件标识符的字符。(继承自 Control) | 
| IsChildControlStateCleared | 获取一个值,该值指示该控件中包含的控件是否具有控件状态。(继承自 Control) | 
| IsTrackingViewState | 获取一个值,用于指示服务器控件是否会将更改保存到其视图状态中。(继承自 Control) | 
| IsViewStateEnabled | 获取一个值,该值指示是否为该控件启用了视图状态。(继承自 Control) | 
| LoadViewStateByID | 获取一个值,该值指示控件是否通过 ID 而不是索引参与加载其视图状态。(继承自 Control) | 
| NamingContainer | 获取对服务器控件的命名容器的引用,此引用创建唯一的命名空间,以区分具有相同 ID 属性值的服务器控件。(继承自 Control) | 
| Page | 获取对包含服务器控件的 Page 实例的引用。(继承自 Control) | 
| Parent | 获取对页 UI 层次结构中服务器控件的父控件的引用。(继承自 Control) | 
| RenderingCompatibility | 获取一个值,该值指定呈现的 HTML 将与之兼容的 ASP.NET 版本。(继承自 Control) | 
| Site | 获取容器信息,该容器在呈现于设计图面上时承载当前控件。(继承自 Control) | 
| SkinID | 获取或设置要应用于控件的外观。(继承自 Control) | 
| TemplateControl | 获取或设置对包含该控件的模板的引用。(继承自 Control) | 
| TemplateSourceDirectory | 获取包含当前服务器控件的 Page 或 UserControl 的虚拟目录。(继承自 Control) | 
| UniqueID | 获取服务器控件的唯一的、以分层形式限定的标识符。(继承自 Control) | 
| ValidateRequestMode | 获取或设置指示控件是否检查来自浏览器的客户端输入是否具有潜在危险值的值。(继承自 Control) | 
| ViewState | 获取状态信息的字典,这些信息使您可以在同一页的多个请求间保存和还原服务器控件的视图状态。(继承自 Control) | 
| ViewStateIgnoresCase | 获取一个值,该值指示 StateBag 对象是否不区分大小写。(继承自 Control) | 
| ViewStateMode | 获取或设置此控件的视图状态模式。(继承自 Control) | 
| Visible | 获取或设置一个值,该值指示服务器控件是否作为 UI 呈现在页上。(继承自 Control) | 
方法
事件
| DataBinding | 当服务器控件绑定到数据源时发生。(继承自 Control) | 
| Disposed | 当从内存释放服务器控件时发生,这是请求 ASP.NET 页时服务器控件生存期的最后阶段。(继承自 Control) | 
| Init | 当服务器控件初始化时发生;初始化是控件生存期的第一步。(继承自 Control) | 
| Load | 当服务器控件加载到 Page 对象中时发生。(继承自 Control) | 
| PreRender | 在加载 Control 对象之后、呈现之前发生。(继承自 Control) | 
| Unload | 当服务器控件从内存中卸载时发生。(继承自 Control) | 
显式接口实现
| IControlBuilderAccessor.ControlBuilder | 有关此成员的说明,请参见 ControlBuilder。(继承自 Control) | 
| IControlDesignerAccessor.GetDesignModeState() | 有关此成员的说明,请参见 GetDesignModeState()。(继承自 Control) | 
| IControlDesignerAccessor.SetDesignModeState(IDictionary) | 有关此成员的说明,请参见 SetDesignModeState(IDictionary)。(继承自 Control) | 
| IControlDesignerAccessor.SetOwnerControl(Control) | 有关此成员的说明,请参见 SetOwnerControl(Control)。(继承自 Control) | 
| IControlDesignerAccessor.UserData | 有关此成员的说明,请参见 UserData。(继承自 Control) | 
| IDataBindingsAccessor.DataBindings | 有关此成员的说明,请参见 DataBindings。(继承自 Control) | 
| IDataBindingsAccessor.HasDataBindings | 有关此成员的说明,请参见 HasDataBindings。(继承自 Control) | 
| IExpressionsAccessor.Expressions | 有关此成员的说明,请参见 Expressions。(继承自 Control) | 
| IExpressionsAccessor.HasExpressions | 有关此成员的说明,请参见 HasExpressions。(继承自 Control) | 
| IParserAccessor.AddParsedSubObject(Object) | 有关此成员的说明,请参见 AddParsedSubObject(Object)。(继承自 Control) | 
扩展方法
| FindDataSourceControl(Control) | 返回与指定控件的数据控件关联的数据源。 | 
| FindFieldTemplate(Control, String) | 返回指定控件的命名容器中指定列的字段模板。 | 
| FindMetaTable(Control) | 返回包含数据控件的元表对象。 | 
| GetDefaultValues(INamingContainer) | 为指定数据控件获取默认值的集合。 | 
| GetMetaTable(INamingContainer) | 为指定数据控件获取表元数据。 | 
| SetMetaTable(INamingContainer, MetaTable) | 为指定数据控件设置表元数据。 | 
| SetMetaTable(INamingContainer, MetaTable, IDictionary<String,Object>) | 为指定数据控件设置表元数据和默认值映射。 | 
| SetMetaTable(INamingContainer, MetaTable, Object) | 为指定数据控件设置表元数据和默认值映射。 | 
| TryGetMetaTable(INamingContainer, MetaTable) | 确定表元数据是否可用。 | 
| EnableDynamicData(INamingContainer, Type) | 为指定数据控件启用动态数据行为。 | 
| EnableDynamicData(INamingContainer, Type, IDictionary<String,Object>) | 为指定数据控件启用动态数据行为。 | 
| EnableDynamicData(INamingContainer, Type, Object) | 为指定数据控件启用动态数据行为。 |