ASP.NET 2.0 主版頁面(Master Pages)

來源:互聯網
上載者:User
ASP.NET 2.0 - 主版頁面(Master Pages)

主版頁面(Master Pages)為網站內的其他頁面提供模版。

主版頁面(Master Pages)

Master Page 使您有能力為 web 應用程式中的所有頁面(或頁面組)建立一致的外觀和行為。

Master Page 為其他頁面提供了模版,帶有共用的布局和功能。Master Page 為內容定義了可被內容頁面覆蓋的預留位置。而輸出結果就是 Master Page 和內容頁面的組合。

內容頁包含您希望顯示的內容。

當使用者請求內容頁時,ASP.NET 會對頁面進行合并以產生輸出,輸出結果對 Master Page 的布局和內容頁面的內容進行了合并。

Master Page 執行個體: 
<%@ Master %>

<html>
<body>
<h1>Standard Header For All Pages</h1>

<asp:ContentPlaceHolder id="CPH1" runat="server">
</asp:ContentPlaceHolder>

</body>
</html> 

Master Page 是一張為其他頁面設計的普通 HTML 模版頁。

@ Master 指令把它定義為一張 master page。

這個 master page 為單獨的內容包含了一個預留位置標籤
<asp:ContentPlaceHolder>

id="CPH1" 屬性標識該預留位置,在相同的 master page 中允許多個預留位置。

該 master page 被儲存為 "master1.master"

注釋:該 master page 也能夠包含代碼,允許動態內容。


內容頁執行個體: 

<%@ Page MasterPageFile="master1.master" %>

<asp:Content ContentPlaceHolderId="CPH1" runat="server">

<h2>Individual Content</h2>
<p>Paragrap 1</p>
<p>Paragrap 2</p>

</asp:Content> 


上面的內容頁是獨立的內容頁面之一。  

@ Page 指令把它定義為一張標準的內容頁面。

該內容頁麵包含了一個內容標籤<asp:Content>,該標籤引用了主版頁面(ContentPlaceHolderId="CPH1")。

該內容頁被儲存為 "mypage1.aspx"

當使用者請求該頁面時,ASP.NET 就會將主版頁面與內容頁進行合并。 

注釋:內容文本必須位於 <asp:Content> 標籤內。該標籤外的文本是不被允許的。

帶有控制項的內容頁 


<%@ Page MasterPageFile="master1.master" %>

<asp:Content ContentPlaceHolderId="CPH1" runat="server">

<h2>W3School</h2>
<form runat="server">
<asp:TextBox id="textbox1" runat="server" />
<asp:Button id="button1" runat="server" text="Button" />
</form>

</asp:Content>
 上面的內容頁示範了如何把 .NET 控制項插入內容頁,就像插入一個普通的頁面中。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.