System.Web.UI.WebControls


.NET Framework 类库
ContentPlaceHolder 类

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

在 ASP.NET 母版页中定义内容区域。

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

语法

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

ContentPlaceHolder 控件在母版页中定义相对内容区域,并呈现在内容页中找到的相关的 Content 控件的所有文本、标记和服务器控件。

Content 控件使用其 ContentPlaceHolderID 属性与 ContentPlaceHolder 关联。将 ContentPlaceHolderID 属性设置为母版页中相关的 ContentPlaceHolder 控件的 ID 属性的值。在母版页中可以声明多个 ContentPlaceHolder

在内容页中,只有一个 Content 控件可以为母版页中的 ContentPlaceHolder 提供内容。但是,在使用某一母版页的每个内容页中,都可以具有不同的与 ContentPlaceHolder 相关联的 Content 控件。例如,可以在母版页中为页标题定义 ContentPlaceHolder。对于使用该母版页的每个内容页,可以添加 Content 控件,该控件为页标题提供文本和标记。

可以指定放置在 ContentPlaceHolder 控件标记内的默认内容,但此内容会替换为相关联的内容页中的任何内容。

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

TopicLocation
如何:为 ASP.NET 母版页创建内容页在 Visual Studio 中生成 ASP .NET Web 应用程序
如何:为 ASP.NET 母版页创建内容页 (Visual Studio)在 Visual Studio 中构建 ASP .NET Web 应用程序
如何:引用 ASP.NET 母版页的内容生成 ASP .NET Web 应用程序
如何:引用 ASP.NET 母版页的内容在 Visual Studio 中生成 ASP .NET Web 应用程序
演练:向网站添加站点导航在 Visual Studio 中构建 ASP .NET Web 应用程序
演练:向网站添加站点导航使用 Visual Web Developer 生成应用程序
演练:在 Visual Web Developer 中创建和使用 ASP.NET 母版页在 Visual Studio 中构建 ASP .NET Web 应用程序
演练:在 Visual Web Developer 中创建和使用 ASP.NET 母版页使用 Visual Web Developer 生成应用程序
示例

下面的代码示例演示如何使用 ContentPlaceHolder 控件定义母版页的内容区域。第一个网页为母版页,并使用 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 中。

Visual Basic
Class SampleMasterClass
         Inherits System.Web.UI.MasterPage
     Dim asitename As String
     Public Property SiteName() As String
       Get
         Return asitename
       End Get
       Set(ByVal Value as String)
         asitename = Value
       End Set
     End Property
End Class
C#
public class SampleMasterClass : System.Web.UI.MasterPage {
     private string sitename;     
     public string SiteName
     {
        get {return(sitename);}
        set {sitename = value;}
     }
}
.NET Framework 安全性

继承层次结构

System.Object
   System.Web.UI.Control
    System.Web.UI.WebControls.ContentPlaceHolder
线程安全

此类型的任何公共静态(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
请参见

标记 :


Page view tracker