69pao国产精品视频-久久精品一区二区二三区-精品国产精品亚洲一本大道-99国产综合一区久久

ASP.NET 母版頁(yè)

asp.net web forms - 母版頁(yè)

母版頁(yè)為您的網(wǎng)站的其他頁(yè)面提供模版。

母版頁(yè)

母版頁(yè)允許您為您的 web 應(yīng)用程序中的所有頁(yè)面(或頁(yè)面組)創(chuàng)建一致的外觀和行為。

母版頁(yè)為其他頁(yè)面提供模版,帶有共享的布局和功能。母版頁(yè)為內(nèi)容定義了可被內(nèi)容頁(yè)覆蓋的占位符。輸出結(jié)果是母版頁(yè)和內(nèi)容頁(yè)的組合。

內(nèi)容頁(yè)包含您想要顯示的內(nèi)容。

當(dāng)用戶請(qǐng)求內(nèi)容頁(yè)時(shí),asp.net 會(huì)對(duì)頁(yè)面進(jìn)行合并以生成結(jié)合了母版頁(yè)布局和內(nèi)容頁(yè)內(nèi)容的輸出。

母版頁(yè)實(shí)例

<%@ master %>

<html>
<body>
<h1>standard header from masterpage</h1>
<asp:contentplaceholder id="cph1" runat="server">
</asp:contentplaceholder>
</body>
</html>

上面的母版頁(yè)是一個(gè)為其他頁(yè)面設(shè)計(jì)的普通 html 模版頁(yè)。

@ master 指令定義它為一個(gè)母版頁(yè)。

母版頁(yè)為單獨(dú)的內(nèi)容包含占位標(biāo)簽 <asp:contentplaceholder>。

id="cph1" 屬性標(biāo)識(shí)占位符,在相同母版頁(yè)中允許多個(gè)占位符。

這個(gè)母版頁(yè)被保存為 "master1.master"。

lamp 注釋:母版頁(yè)也能夠包含代碼,允許動(dòng)態(tài)的內(nèi)容。

內(nèi)容頁(yè)實(shí)例

<%@ page masterpagefile="master1.master" %>

<asp:content contentplaceholderid="cph1" runat="server">
<h2>individual content</h2>
<p>paragraph 1</p>
<p>paragraph 2</p>
</asp:content>

上面的內(nèi)容頁(yè)是站點(diǎn)中獨(dú)立的內(nèi)容頁(yè)中的一個(gè)。

@ page 指令定義它為一個(gè)標(biāo)準(zhǔn)的內(nèi)容頁(yè)。

內(nèi)容頁(yè)包含內(nèi)容標(biāo)簽 <asp:content>,該標(biāo)簽引用了母版頁(yè)(contentplaceholderid="cph1")。

這個(gè)內(nèi)容頁(yè)被保存為 "mypage1.aspx"。

當(dāng)用戶請(qǐng)求該頁(yè)面時(shí),asp.net 就會(huì)將母版頁(yè)與內(nèi)容頁(yè)進(jìn)行合并。

點(diǎn)擊這里顯示 mypage1.aspx

lamp注釋:內(nèi)容文本必須位于 <asp:content> 標(biāo)簽內(nèi)部。標(biāo)簽外的內(nèi)容文本是不允許的。

帶控件的內(nèi)容頁(yè)

<%@ page masterpagefile="master1.master" %>

<asp:content contentplaceholderid="cph1" runat="server">
<h2>yapf</h2>
<form runat="server">
<asp:textbox id="textbox1" runat="server" />
<asp:button id="button1" runat="server" text="button" />
</form>
</asp:content>

上面的內(nèi)容頁(yè)演示了如何把 .net 控件插入內(nèi)容頁(yè),就像插入一個(gè)普通的頁(yè)面中。

點(diǎn)擊這里顯示 mypage2.aspx


相關(guān)文章