生活随笔
收集整理的這篇文章主要介紹了
了解Master Pages库
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
aspnet forums界面的最關鍵的問題首先在于它使用了MetaBuilders的Master Pages 控件. 到http://www.metabuilders.com/Tools/MasterPages.aspx處下載此控件來研究一下: 一、Master Pages包括四個類: (1)Content: This control contains the content for a particular region? ??????????? 此類控件包含真實內容 (2)ContentContainer: This control serves two distincts purposes: - it marks the location where the Master Page will be inserted into the Page - it contains the various Content sections that will be matched to the Master Page's Region controls (based on their ID's). ??????????????????? 此控件有兩個意圖: ??????????????????? ·作為一個定位標志,標識Master Page將被插入到頁中; ??????????????????? ·與Region Controls相匹配 (3)NoBugForm: A server form that does not cause a problem by being inside a master page or other naming container. ???????????? 無錯form。可以放心使用 (4)Region: The control marks a place holder for content in a master page? ???????????占位控件 二、我們通過分析default.aspx來看看Master Page使用方式 (1)default.aspx的內容如下:
< mp:ContentContainer?runat = " server " ?id = " MPContainer " ?MasterPageFile = " ~/Themes/MasterPage.ascx " > ? ???? < mp:Content?id = " HeadTag " ?runat = " server " > ? ???????? < meta?http - equiv = " Refresh " ?content = " 300 " ? /> ? ???? </ mp:Content > ? ???? < mp:Content?id = " MainContent " ?runat = " server " > ? ???????? < Forums:ForumGroupView?runat = " server " ? /> ? ???? </ mp:Content > ? </ mp:ContentContainer > ? mp:ContentContainer是一個容器,MasterPageFile="~/Themes/MasterPage.ascx是它最重要的屬性,指向了一個ascx控件頁。其實,這個ascx控件并不是一個真的ascx控件,而是一個頁面框架。它提供了default.aspx頁面的主結構,然后在其中留出了空白,讓default.aspx來填空。 (2)再來仔細看看masterpage.ascx的內容
< html > ? < head > ? <!-- 標題 --> ? < Forums:PageTitle? runat ="server" ? /> ? <!-- 風格定義 --> ? < Forums:Style? id ="Style1" ?runat ="server" ? /> ? <!-- 頭標簽 --> ? < mp:region? id ="HeadTag" ?runat ="server" ? /> ? </ head > ? < body? leftmargin ="0" ?topmargin ="0" ?marginwidth ="0" ?marginheight ="0" > ? <!-- ?*********?NoBugForm:START?*************?// --> ? < mp:NoBugForm? runat ="server" > ? < mp:region? id ="MainContent" ?runat ="server" > Default?main?content </ mp:region > ? </ mp:NoBugForm > ? <!-- ?*********?NoBugForm:END?*************?// --> ? <!-- ?*********?Footer:START?*************?// --> ? < Forums:Footer? runat ="server" ? />< br? /> ? <!-- ?*********?Footer:END?*************?// --> ? </ body > ? </ html > ? 首先,它有html文件的<head>,在<head>中留下了不小的地方放自定義控件,Forums:PageTitle 和Forums:Style 然后,在Body中有一個NoBugForm,這個的作用先猜測一下,可能是指用于mp控件的form。 最為重要的是它有一個 <mp:region id="MainContent" runat="server">Default main content</mp:region> region是一個占位控件,它給誰占的位置呢?看看default.aspx就明白了: <mp:Content id="MainContent" runat="server"> ?? <Forums:ForumGroupView runat="server" /> </mp:Content> 看到了嗎?content中的id與region的id相匹配。結果,default.aspx將會在這兒顯示出來。 ? 三、優點考慮: 現在看來master pages的結構也相對簡單。但為什么要使用這種方式而不是直接使用ascx控件呢? 關鍵在于換膚。 asp forums為了實現換膚的方便而使用了一個專門的ascx文件作為框架頁。而通常的ascx文件是不可能作為框架頁的,它只能是一個頁面中的一部分,我們還需要一個aspx或html文件作為框架頁。如果框架頁改變了,則所有使用此框架的頁面全部都要改過。這在dreamweaver中可以使用模板來實現,但也相當不方便。(我沒有用過模板,只知道其是自動更改使用模板的頁)但使用期master pages結構后只需要改變一個文件或幾個文件就可以實現。 關于asp.net 2.0 的MasterPage,可以參考: http://www.microsoft.com/taiwan/msdn/library/2004/oct-2004/masterpages.htm
轉載于:https://www.cnblogs.com/fanrsh/archive/2006/06/01/414820.html
總結
以上是生活随笔 為你收集整理的了解Master Pages库 的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔 網站內容還不錯,歡迎將生活随笔 推薦給好友。