System.Web.UI.WebControls 命 ...


.NET Framework 类库
Content 类

更新:2007 年 11 月

保存文本、标记和服务器控件以呈现给母版页中的 ContentPlaceHolder 控件。

命名空间:  System.Web.UI.WebControls
程序集:  System.Web(在 System.Web.dll 中)

语法

Visual Basic(声明)
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class Content _
    Inherits Control _
    Implements INamingContainer
Visual Basic (用法)
Dim instance As Content
C#
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class Content : Control, INamingContainer
Visual C++
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class Content : public Control, 
    INamingContainer
J#
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal) */
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal) */
public class Content extends Control implements INamingContainer
JScript
public class Content extends Control implements INamingContainer
ASP.NET
<asp:Content />
备注

Content 控件是内容页的内容和控件的容器。Content 控件仅与定义相应的 ContentPlaceHolder 控件的母版页一起使用。Content 控件在运行时不添加到控件层次结构。相反,Content 控件中的内容直接合并到相应的 ContentPlaceHolder 控件中。

Content 控件使用它的 ContentPlaceHolderID 属性与一个 ContentPlaceHolder 关联。将 ContentPlaceHolderID 属性设置为母版页中 ContentPlaceHolder 控件的 ID 属性的值。调用内容页的 URL 时,Content 控件中包含的所有文本、标记和服务器控件都会呈现给母版页上的 ContentPlaceHolder,并且浏览器的地址栏将显示内容页的名称。

有关母版页和内容页的更多信息,请参见 ASP.NET 母版页概述

TopicLocation
如何:为 ASP.NET 母版页创建内容页在 Visual Studio 中生成 ASP .NET Web 应用程序
如何:为 ASP.NET 母版页创建内容页 (Visual Studio)在 Visual Studio 中构建 ASP .NET Web 应用程序
演练:在 Visual Web Developer 中创建和使用 ASP.NET 母版页在 Visual Studio 中构建 ASP .NET Web 应用程序
演练:在 Visual Web Developer 中创建和使用 ASP.NET 母版页使用 Visual Web Developer 生成应用程序
示例

下面的代码示例演示如何使用 Content 控件来定义母版页的内容。第一个网页是母版页并且使用 ContentPlaceHolder 控件来定义内容区域。

Visual Basic
<%@ 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>
C#
<%@ 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

C#
<%@ Page Language="C#" MasterPageFile="~/MasterPageSample_1cs.master" Title="Content Page"%>

<asp:content 
    runat="server"
    contentplaceholderid="ContentPlaceHolder1" >Hello, Master Pages!</asp:content>
Visual Basic
<%@ 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
另请参见

参考

其他资源

标记 :


Page view tracker