1 / 18

網際網路程式設計

網際網路程式設計. 主版頁面. 參考書. 李育丞( 2012 ), ASP.NET 網頁資料庫程式設計, 博碩文化股份有限公司, ISBN 978-986-201-628-2 (書號 PG31204 ). 大綱. 主版頁面與內容頁面的技術內含 主版頁面與內容頁面的使用 主版頁面與內容頁面的設計技巧 存取主版頁面內的控制項. 8.1 主版頁面簡介. 套用範本的所有網頁基本外型都一樣 頁首 Banner 選單區 Menu 頁 尾 Footer 只要修改範本,所有的網頁全部更新 維護方便 主版頁面 (Master Page)

awena
Télécharger la présentation

網際網路程式設計

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 網際網路程式設計 主版頁面

  2. 參考書 李育丞(2012), ASP.NET網頁資料庫程式設計, 博碩文化股份有限公司, ISBN 978-986-201-628-2 (書號 PG31204)

  3. 大綱 主版頁面與內容頁面的技術內含 主版頁面與內容頁面的使用 主版頁面與內容頁面的設計技巧 存取主版頁面內的控制項

  4. 8.1 主版頁面簡介 • 套用範本的所有網頁基本外型都一樣 • 頁首 Banner • 選單區 Menu • 頁尾 Footer • 只要修改範本,所有的網頁全部更新 • 維護方便 • 主版頁面(Master Page) • 內容頁面(Content Page)

  5. 1. 主版頁面(Master Page) • 副檔名為 *.master • 內容:靜態文字、HTML 標籤、JavaScript 用戶端指令碼和伺服器控制項 • 主版頁面使用 @Master 指示詞設定網頁屬性 <%@ Master Language="C#" CodeFile="MyMasterPage.master.cs" Inherits="MyMasterPage" %>

  6. 1. 主版頁面(Master Page) • 一致性功能、網頁版面 • 可以在主版頁面使用HTML表格進行網頁編排、使用CSS配置網頁外觀、放置Flash廣告動畫、使用巡覽控制項導覽網站、加入建立網站公司的Logo及著作權注意事項 • 內含一個或多個的 ContentPlaceHolder預留空間給內容頁面 <asp:ContentPlaceHolder ID="物件識別名稱" runat="server"> <!--預留空間提供內容頁面放置其它內容 --> </asp:ContentPlaceHolder >

  7. 2. 內容頁面(Content Page) • 一個 ASP .NET 網頁 • 副檔名為 *.aspx • 不含 <html>、<head> 或 <body> 等標籤 • 必須使用 @Page 指示詞的 MasterPageFile屬性指定主版頁面 • 使用 Title 屬性指定內容頁面的標題 • Content 控制項 • 放置內容頁面欲顯示的網頁元素與Web控制項 • ContentPlaceHolder ID 屬性指定對應到主版面頁的ContentPlaceHolder控制項

  8. 2. 內容頁面(Content Page) <%@ Page Language="C#" MasterPageFile="~/Master1.master" Title="博碩文化"%> <asp:Content ID="物件識別名稱" runat="server" ContentPlaceHolderID="主版頁面ContentPlaceHolder物件識別名稱" > <!--內容頁面可在此放置網頁元素或Web控制項 --> </asp:Content >

  9. 3. 內容頁面的執行 • 當用戶端瀏覽器要求瀏覽內容頁面時 • 內容頁面與主版頁面合併 • 將合併後的結果顯示於用戶端的瀏覽器上

  10. 8.2 主版頁面與內容頁面的使用 • ASP.NET 4.0 的 Web Form 範本預設使用主版頁面 • 內含 登入控制項 • 選單:『首頁』、『關於』

  11. 8.3 存取主版頁面內的控制項 • 在內容頁面中使用 Master.FindControl() 方法取得主版頁面的控制項物件參考 控制項型別 變數 = (控制項型別)Master.FindControl("物件識別名稱") ; 變數.屬性 = 屬性值 ;

  12. 8.3 存取主版頁面內的控制項 • 主版頁面內含 lblMsg標籤控制項 • 在內容頁面內將主版頁面的 lblMsg的 Text 屬性值設為 "歡迎光臨",ForeColor前景色設為藍色 Label lbl = (Label) Master.FindControl("lblMsg") ; lbl.Text = "歡迎光臨" ; lbl.ForeColor = System.Drawing.Color.Blue ;

More Related