偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

ASP.NET1.1實現(xiàn)仿2.0的MasterPage功能

開發(fā) 后端
本文介紹了ASP.NET1.1實現(xiàn)仿ASP.NET2.0的MasterPage效果。

在asp.net 2.0中,提供了一個masterpage的功能,它可以讓我們很方便的完成頁面的整體結(jié)構(gòu)相同的網(wǎng)站,而且后期修改界面的時候只要修改一下masterpage即可,無需一個個界面進行修改,這樣就大大的方便了開發(fā)人員.其實類似這種技術(shù)在asp.net1.1中也可以實現(xiàn).

思路分析

對于可以用mastespanpage的網(wǎng)站來說,它的頁面結(jié)構(gòu)大部份是一至的,比如頂部、底部都是一樣的,只不過左右側(cè)顯示的內(nèi)容不同。這個時候,你不妨把左右兩側(cè)的內(nèi)容也分別放在用戶控件中,然后根據(jù)當(dāng)前的訪問地址來動態(tài)加載用戶控件,這樣到時候只要修改動態(tài)加載的用戶控件的內(nèi)容,或是masterpage的框架,即可實現(xiàn)修理網(wǎng)站的目的。

實現(xiàn)過程

首先取得當(dāng)前訪問的文件地址,代碼如下:

  1. //取得當(dāng)前訪問的路徑  
  2. sspaning sspanrequesturl = request.url.absolutepath.tosspaning();  
  3. //取得當(dāng)前訪問的文件名,并轉(zhuǎn)換成小寫  
  4. sspaning sspannowviewfile = sspanrequesturl.subsspaning((sspanrequesturl.lastindexof(@"/") + 1)).trim().tolower();  

然后點擊“添加?添加web用戶控件”新建三個用戶控件,分別命名為masterpage.ascx、head.ascx和foot.ascx,在masterpage.ascx中添加一個三行兩列的表格,然后將head.ascx和foot.ascx控件拖到masterpage.ascx中,同時在左右兩側(cè)均添加一個placeholder控件,分別命名為hldleftconspanol和hldrightconspanol,完成后效果如下:

  1. head.ascx hldleftconspanol hldrightconspanol foot.ascx 

此時只要將masterpage.ascx拖到具體的頁面中,比如index.aspx,運行后就會顯示頂部、底部的內(nèi)容。接下來要根據(jù)當(dāng)前訪問的文件地址,確定動態(tài)加載哪些用戶控件到左右兩側(cè)位置,這部份操作在masterpage.ascx.cs中完成。代碼如下:

  1. //ASP.NET1.1
  2. switch(sspannowviewfile)  
  3. {  
  4. //如果當(dāng)前訪問的是首頁  
  5. case "index.aspx":   
  6. //創(chuàng)建用戶控件類的對象,類名與用戶控件的名稱是相同的   
  7. conspanol_index_indexrightconspanol indexrightconspanol;  
  8. //加載用戶控件  
  9. indexrightconspanol = (conspanol_index_indexrightconspanol)page.loadconspanol("conspanol_index_indexrightconspanol.ascx");  
  10. //在右側(cè)的placeholder控件中顯示用戶控件   
  11. plhrightconspanol.conspanols.add(indexrightconspanol);  
  12. break;  
  13. //加載會員注冊部份  
  14. case "register.aspx":   
  15. conspanol_login_register register;  
  16. register = (conspanol_login_register)page.loadconspanol("conspanol_login_register.ascx");  
  17. plhrightconspanol.conspanols.add(register);  
  18. break;  
  19. default:   
  20. indexrightconspanol = (conspanol_index_indexrightconspanol)page.loadconspanol("conspanol_index_indexrightconspanol.ascx");  
  21. plhrightconspanol.conspanols.add(indexrightconspanol);  
  22. break;  
  23. }  

添加了以上代碼后,如果訪問的頁面是index.aspx,在index.aspx頁右側(cè),就會加載conspanol_index_indexrightconspanol.ascx控件的內(nèi)容,如果訪問的是register.aspx頁,右側(cè)就會加載conspanol_login_register.ascx控件的內(nèi)容.

這樣就使得asp.net1.1實現(xiàn)了masterpage的功能.

【編輯推薦】

  1. ASP.NET關(guān)機代碼(Windows為本機)
  2. ASP.NET QueryString亂碼解決問題
  3. ASP.NET畫面跳轉(zhuǎn)實現(xiàn)及其傳值問題解決方案
  4. ASP.NET Web應(yīng)用程序用戶操作信息描述類
  5. ASP.NET之父強烈推薦:ASP.NET AJAX著作
責(zé)任編輯:book05 來源: blogbus
相關(guān)推薦

2009-07-29 14:59:26

asp.net1.1ASP.NET2.0

2009-07-29 15:17:42

驗證控件ASP.NET1.1ASP.NET2.0

2009-07-29 15:58:54

靜態(tài)文件處理ASP.NET

2009-07-29 15:51:29

ASP.NET中執(zhí)行w

2009-07-29 11:29:16

ASP.NET1.1ASP.NET2.0

2009-07-29 15:26:43

ASP.NET連接Or

2009-07-29 15:06:16

asp.net1.1asp.net2.0

2009-07-29 16:04:39

ASP.NET1.1驗

2009-07-29 15:42:37

asp.net1.1開

2009-07-23 13:36:03

2009-08-04 14:44:40

callback實現(xiàn)機ASP.NET2.0

2009-12-10 17:47:01

ASP.NET 2.0

2009-07-22 17:23:03

XmlDataSourASP.NET 2.0

2009-12-03 13:34:36

Visual Stud

2009-12-14 10:03:16

ASP.NET 2.0

2009-07-30 13:18:31

2009-07-30 15:17:16

ASP.NET 2.0

2009-07-22 16:02:39

ASP.NET MVCPagedList

2009-07-21 15:27:12

ASP.NET 2.0

2009-07-22 17:28:07

CSS文件ASP.NET 2.0
點贊
收藏

51CTO技術(shù)棧公眾號