Content Class

Holds text, markup, and server controls to render to a ContentPlaceHolder control in a master page.

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

[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class Content : Control, INamingContainer
<asp:Content />

A Content control is a container for the content and controls of a content page. A Content control is used only with a master page that defines a corresponding ContentPlaceHolder control. A Content control is not added to the control hierarchy at runtime. Instead, the contents within the Content control are directly merged into the corresponding ContentPlaceHolder control.

The Content control is associated with a ContentPlaceHolder using its ContentPlaceHolderID property. Set the ContentPlaceHolderID property to the value of the ID property of a ContentPlaceHolder control in a master page. When the URL of the content page is called, all text, markup, and server controls that are contained within the Content control are rendered to the ContentPlaceHolder on the master page, and the address bar of the browser will show the name of the content page.

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

TopicLocation
Walkthrough: Creating and Using ASP.NET Master Pages in Visual Web DeveloperBuilding 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

The following code example shows how to use the Content control to define the content 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 how to use a content page for the preceding master page. The text, markup, and any server controls that are defined within the Content control template are rendered to the ContentPlaceHolder on the master page.

<%@ Page Language="C#" MasterPageFile="~/MasterPageSample_1cs.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

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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, 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
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft