共用方式為


ContentPlaceHolder Web Server Control Declarative Syntax 

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

<asp: ContentPlaceHolder
        EnableViewState="True|False"
    ID="string"
    OnDataBinding="DataBinding event handler"
    OnDisposed="Disposed event handler"
    OnInit="Init event handler"
    OnLoad="Load event handler"
    OnPreRender="PreRender event handler"
    OnUnload="Unload event handler"
    runat="server"
    Visible="True|False"
>
        <!-- child controls -->
</asp:ContentPlaceHolder>

Remarks

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 that is 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. For more information about master pages, see ASP.NET Master Pages.

Example

The following code example shows how to use the ContentPlaceHolder control to define a content region for a master page. The Web page is a master page and defines a content region using a ContentPlaceHolder control. A content page references this master page by setting the MasterPageFile attribute of the @ Page directive and defining Content controls.

<%@ 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>

See Also

Reference

ContentPlaceHolder

Other Resources

ASP.NET Master Pages