注意:此类在 .NET Framework 2.0 版中是新增的。
保存文本、标记和服务器控件以呈现给母版页中的
ContentPlaceHolder 控件。
命名空间:System.Web.UI.WebControls
程序集:System.Web(在 system.web.dll 中)
Public Class Content
Inherits Control
Implements INamingContainer
public class Content : Control, INamingContainer
public ref class Content : public Control, INamingContainer
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
此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。
Windows 98、Windows 2000 SP4、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
.NET Framework
受以下版本支持:2.0