Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
ContentPlaceHolder Class

Updated: November 2007

Defines a region for content in an ASP.NET master page.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

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

A ContentPlaceHolder control defines a relative region for content in a master page, and renders all text, markup, and server controls from a related Content control found in a content page.

A Content control is associated with a ContentPlaceHolder using its ContentPlaceHolderID property. Set the ContentPlaceHolderID property to the value of the ID property of the related ContentPlaceHolder control in a master page. More than one ContentPlaceHolder can be declared in a master page.

Within a content page, only one Content control can supply the content for a ContentPlaceHolder in the master page. However, in each content page that uses a master page, you can have separate Content controls associated with the ContentPlaceHolder. For example, you can define the ContentPlaceHolder for the page title in a master page. For each content page that uses the master page, you can add a Content control that supplies the text and markup for the page title.

Note:

For XHtml compliance, an empty title element is created if a title has not been defined or cannot be found.

You can specify default content placed within the ContentPlaceHolder control tags, but this content is replaced by any content in an associated content page.

For more information about master pages and content pages, see ASP.NET Master Pages.

TopicLocation
How to: Create Content Pages for an ASP.NET Master PageBuilding ASP .NET Web Applications in Visual Studio
How to: Create Content Pages for an ASP.NET Master Page (Visual Studio)Building ASP .NET Web Applications in Visual Studio
How to: Reference ASP.NET Master Page ContentBuilding ASP .NET Web Applications
How to: Reference ASP.NET Master Page ContentBuilding ASP .NET Web Applications
How to: Reference ASP.NET Master Page ContentBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Adding Site Navigation to a Web SiteBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Adding Site Navigation to a Web SiteBuilding Applications with Visual Web Developer
Walkthrough: Creating and Using ASP.NET Master Pages in Visual Web DeveloperBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Creating and Using ASP.NET Master Pages in Visual Web DeveloperBuilding Applications with Visual Web Developer

The following code example shows how the ContentPlaceHolder control is used to define a content region for a master page. The first Web page is a master page, and defines a content region using a ContentPlaceHolder control.

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>

The following code example demonstrates a content page for the preceding master page. The text, markup, and any server controls defined within the Content control template are rendered to the ContentPlaceHolder on the master page.

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;}
     }
}

System..::.Object
  System.Web.UI..::.Control
    System.Web.UI.WebControls..::.ContentPlaceHolder
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker