更新:2007 年 11 月
命名空间:
System.Web.UI.WebControls 程序集:
System.Web(在 System.Web.dll 中)
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class Content _
Inherits Control _
Implements INamingContainer
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class Content : Control, INamingContainer
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class Content : public Control,
INamingContainer
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal) */
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal) */
public class Content extends Control implements INamingContainer
public class Content extends Control implements INamingContainer
Content 控件是内容页的内容和控件的容器。Content 控件仅与定义相应的 ContentPlaceHolder 控件的母版页一起使用。Content 控件在运行时不添加到控件层次结构。相反,Content 控件中的内容直接合并到相应的 ContentPlaceHolder 控件中。
Content 控件使用它的 ContentPlaceHolderID 属性与一个 ContentPlaceHolder 关联。将 ContentPlaceHolderID 属性设置为母版页中 ContentPlaceHolder 控件的 ID 属性的值。调用内容页的 URL 时,Content 控件中包含的所有文本、标记和服务器控件都会呈现给母版页上的 ContentPlaceHolder,并且浏览器的地址栏将显示内容页的名称。
有关母版页和内容页的更多信息,请参见 ASP.NET 母版页概述。
下面的代码示例演示如何使用 Content 控件来定义母版页的内容。第一个网页是母版页并且使用 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。
<%@ 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>
System..::.Object
System.Web.UI..::.Control
System.Web.UI.WebControls..::.Content
此类型的任何公共 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
参考
其他资源