asp.NET中使用include

來源:互聯網
上載者:User
A common way to build the navigation and layout for an ASP-driven website is to use include files. Most advanced ASP developers know that when you do this, it is best to encapsulate the functionality of the include file in a Sub or Function, and then to call this routine from the page that is including the file. This avoids problems with variable scope, allows parameters to be passed easily to the include file, and makes the code easier to read.
As these sites are migrated to use ASP.NET, it is likely that classic ASP and ASP.NET pages will exist side-by-side, which is one of the touted advantages of ASP.NET. Unfortunately, there is no built-in way for an ASP.NET page to take advantage of a classic ASP include file, which means that the obvious solution if you want to maintain a consistent look and feel is to duplicate the look of the classic ASP template in an ASP.NET user control. Unfortunately, this means duplicating presentation logic, and inevitably, the classic ASP template and the ASP.NET template will get out of sync.
To overcome this problem, I built a simple user control that uses ASP.NET's built-in page-scraping library, HTTPWebResponse, to grab a template ASP file and render it in my .aspx page. The template ASP file is simply a page that includes my presentation logic include file, and calls the functions to render the HTML, passing through any querystring parameters it has to those functions (such as for page title for a header include file).
For this demonstration, there are six files:
layout_sample.asp - this ASP page uses the include file the standard Classic ASP way.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.