Use include in asp. NET

Source: Internet
Author: User
Tags classic asp

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 contains des my presentation logic include file, and callthe 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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.