母版頁(Master Pages)為網(wǎng)站內(nèi)的其他頁面提供模版。
Master Page 使您有能力為 web 應(yīng)用程序中的所有頁面(或頁面組)創(chuàng)建一致的外觀和行為。
Master Page 為其他頁面提供了模版,帶有共享的布局和功能。Master Page 為內(nèi)容定義了可被內(nèi)容頁面覆蓋的占位符。而輸出結(jié)果就是 Master Page 和內(nèi)容頁面的組合。
內(nèi)容頁包含您希望顯示的內(nèi)容。本文是網(wǎng)頁教學(xué)www.webjx.com收集整理或者原創(chuàng)內(nèi)容,轉(zhuǎn)載請注明出處!
當(dāng)用戶請求內(nèi)容頁時,ASP.NET 會對頁面進行合并以生成輸出,輸出結(jié)果對 Master Page 的布局和內(nèi)容頁面的內(nèi)容進行了合并。
<%@ Master %> <html> <body> <h1>Standard Header For All Pages</h1> <asp:ContentPlaceHolder id="CPH1" runat="server"> </asp:ContentPlaceHolder> </body> </html>
Master Page 是一張為其他頁面設(shè)計的普通 HTML 模版頁。
@ Master 指令把它定義為一個張 master page。
這個 master page 為單獨的內(nèi)容包含了一個占位符標簽 <asp:ContentPlaceHolder>。
id="CPH1" 屬性標識該占位符,在相同的 master page 中允許多個占位符。
該 master page 被保存為 "master1.master"。
注釋:該 master page 也能夠包含代碼,允許動態(tài)的內(nèi)容。
<%@ Page MasterPageFile="master1.master" %> <asp:Content ContentPlaceHolderId="CPH1" runat="server"> <h2>Individual Content</h2> <p>Paragrap 1</p> <p>Paragrap 2</p> </asp:Content>
上面的內(nèi)容頁是獨立的內(nèi)容頁面之一。
@ Page 指令把它定義為一張標準的內(nèi)容頁面。
該內(nèi)容頁面包含了一個內(nèi)容標簽<asp:Content>,該標簽引用了母版頁(ContentPlaceHolderId="CPH1")。
該內(nèi)容頁被保存為 "mypage1.aspx"。
當(dāng)用戶請求該頁面時,ASP.NET 就會將母版頁與內(nèi)容頁進行合并。
點擊這里顯示 mypage1.aspx。
注釋:內(nèi)容文本必須位于 <asp:Content> 標簽內(nèi)。該標簽外的文本是不被允許的。
<%@ Page MasterPageFile="master1.master" %> <asp:Content ContentPlaceHolderId="CPH1" runat="server"> <h2>Webjx.Com</h2> <form runat="server"> <asp:TextBox id="textbox1" runat="server" /> <asp:Button id="button1" runat="server" text="Button" /> </form> </asp:Content>
上面的內(nèi)容頁演示了如何把 .NET 控件插入內(nèi)容頁,就像插入一個普通的頁面中。