Export (0) Print
Expand All

ContentPlaceHolder Class

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

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

public class ContentPlaceHolder : Control, INamingContainer
public class ContentPlaceHolder extends Control implements INamingContainer
public class ContentPlaceHolder extends Control implements INamingContainer
Not applicable.

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.

NoteNote:

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: Reference ASP.NET Master Page ContentBuilding ASP .NET Web Applications
How to: Reference ASP.NET Master Page ContentBuilding ASP .NET Web Applications
How to: Create Content Pages for an ASP.NET Master Page (Visual Studio)Building ASP .NET Web Applications in Visual Studio
Walkthrough: Creating and Using ASP.NET Master Pages in Visual Web DeveloperBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Adding Site Navigation to a Web SiteBuilding ASP .NET Web Applications in Visual Studio

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.

<%@ Master Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<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.

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 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft