Share via


Content Web Server Control Declarative Syntax 

Creates a server control that contains text, markup, and other server controls that are rendered to a ContentPlaceHolder control in a master page.

<asp:Content
    ContentPlaceHolderID="string"
    EnableViewState="True|False"
    ID="string"
    runat="server">
    Visible="True|False"
        <!-- child controls -->
</asp:Content>

Remarks

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 a stand-alone control. For more information on master pages, see ASP.NET Master Pages.

Example

The section contains two code examples. The first code example demonstrates how to use the Content control to define the content for a master page. The second code example demonstrates how to use a content page for the master page that is used in the first code example.

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="VB" %>
<!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>
<%@ 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 master page that is used in the preceding code example. 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>
<%@ Page Language="VB" MasterPageFile="~/MasterPageSample_1vb.master" Title="Content Page"%>

<asp:content 
    runat="server"
    contentplaceholderid="ContentPlaceHolder1" >Hello, Master Pages!</asp:content>

See Also

Reference

Content

Other Resources

ASP.NET Master Pages