共用方式為


ContentPlaceHolder Web 伺服器控制項宣告式語法

更新:2007 年 11 月

在 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>

備註

ContentPlaceHolder 控制項會在主版頁面中為內容定義相對區域,並呈現來自在內容頁面中找到之相關 Content 控制項的所有文字、標記和伺服器控制項。

Content 控制項會使用其 ContentPlaceHolderID 屬性,與 ContentPlaceHolder 產生關聯。將 ContentPlaceHolderID 屬性設定為主版頁面中相關 ContentPlaceHolder 控制項的 ID 屬性值。一個以上的 ContentPlaceHolder 可在主版頁面中宣告。如需主版頁面的詳細資訊,請參閱 ASP.NET 主版頁面

範例

下列程式碼範例示範如何使用 ContentPlaceHolder 控制項定義主版頁面的內容區域。Web 網頁是主版頁面,它會使用 ContentPlaceHolder 控制項來定義內容區域。內容頁面藉由設定 @ Page 指示詞的 MasterPageFile 屬性和定義 Content 控制項來參考這個主版頁面。

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

請參閱

參考

ContentPlaceHolder

其他資源

ASP.NET 主版頁面