Content 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
保存文本、标记和服务器控件以呈现给母版页中的 ContentPlaceHolder 控件。
public ref class Content : System::Web::UI::Controlpublic class Content : System.Web.UI.Controltype Content = class
    inherit Control
    interface INamingContainerPublic Class Content
Inherits Control- 继承
- 实现
示例
下面的代码示例演示如何使用 Content 控件定义母版页的内容。 第一个网页是母版页,使用 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 母版页上的 。
<%@ 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>  
注解
Content控件是内容页的内容和控件的容器。 控件 Content 仅用于定义相应 ContentPlaceHolder 控件的母版页。 Content控件在运行时不会添加到控件层次结构中。 相反,控件中 Content 的内容直接合并到相应的 ContentPlaceHolder 控件中。
控件Content使用其 ContentPlaceHolderID 属性与 ContentPlaceHolder 相关联。 将 ContentPlaceHolderID 属性设置为母版页中控件的 ContentPlaceHolder 属性的值ID。 调用内容页的 URL 时,控件中包含的 Content 所有文本、标记和服务器控件都将呈现到 ContentPlaceHolder 母版页上的 ,浏览器的地址栏将显示内容页的名称。
有关母版页和内容页的详细信息,请参阅 ASP.NET 母版页。
声明性语法
<asp:Content  
    ContentPlaceHolderID="string"  
    EnableViewState="True|False"  
    ID="string"  
    runat="server">  
    Visible="True|False"  
        <!-- child controls -->  
</asp:Content>  
构造函数
| Content() | 初始化 CompositeDataBoundControl 类的新实例。 | 
属性
| Adapter | 获取控件的浏览器特定适配器。(继承自 Control) | 
| AppRelativeTemplateSourceDirectory | 获取或设置包含该控件的 Page 或 UserControl 对象的应用程序相对虚拟目录。(继承自 Control) | 
| BindingContainer | 获取包含该控件的数据绑定的控件。(继承自 Control) | 
| ChildControlsCreated | 获取一个值,该值指示是否已创建服务器控件的子控件。(继承自 Control) | 
| ClientID | 获取由 ASP.NET 生成的 HTML 标记的控件 ID。(继承自 Control) | 
| ClientIDMode | 获取或设置用于生成 ClientID 属性值的算法。(继承自 Control) | 
| ClientIDSeparator | 获取一个字符值,该值表示 ClientID 属性中使用的分隔符字符。(继承自 Control) | 
| ContentPlaceHolderID | 获取或设置与当前内容关联的 ContentPlaceHolder 控件的 ID。 | 
| 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 | 控件绑定到数据源时发生。 | 
| Disposed | 控件从内存中释放时发生。 | 
| Init | 在初始化控件时发生。 | 
| Load | 服务器控件加载到 Page 控件中时发生。 | 
| PreRender | 服务器控件将要呈现给其包含的 Page 控件时发生。 | 
| Unload | 当服务器控件从内存中卸载时发生。 | 
显式接口实现
| 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) | 为指定数据控件启用动态数据行为。 |