请单击以进行评分并提供反馈
MSDN
MSDN Library
.NET 开发
先前版本
Content 类

  开启低带宽视图
此页面仅适用于
Microsoft Visual Studio 2005/.NET Framework 2.0

同时提供下列产品的其他版本:
.NET Framework 类库
Content 类

注意:此类在 .NET Framework 2.0 版中是新增的。

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

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

Visual Basic(声明)
Public Class Content
    Inherits Control
    Implements INamingContainer
Visual Basic(用法)
Dim instance As Content
C#
public class Content : Control, INamingContainer
C++
public ref class Content : public Control, INamingContainer
J#
public class Content extends Control implements INamingContainer
JScript
public class Content extends Control implements INamingContainer

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>
  • AspNetHostingPermission  用于在宿主环境中运行 Content 控件。关联的枚举:Minimal
  • AspNetHostingPermission  用于在宿主环境中运行 Content 控件。关联的枚举:Minimal
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
社区内容   什么是社区内容?
添加新内容 RSS  批注
Processing
© 2009 Microsoft Corporation 版权所有。 保留所有权利  |  商标  |  隐私权声明
Page view tracker