ASP 101 - Active Server Pages 101 - Web01
The Place ASP Developers Go!

Please visit our partners

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates

ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash

 Top ASP 101 Stories Top ASP 101 Stories
Getting Scripts to Run on a Schedule
The Top 10 ASP Links @
What is and Why Do I Need It?

Handling "File In Use" Errors when Updating an Access DB
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates

Page Template Functionality

by Paul from Cactusoft Ltd. -

Setting the code up

Unzip everything to a folder on your desktop and copy the entire contents to a new web. There are no databases in this sample and nothing exotic in folder settings is required (other than scripts permissions for the ASPs of course!).

Go to the new web you've created and you should see the first page.

What it does

This code formats pages of a web site dynamically, basing the layout, colours and formatting contained in an HTML template file which some custom tags we've defined. Running a web site from a template in this way has a number of advantages we'll look at later.

How it does it

The buildpage.asp file needs to be included at the top of all content pages. It contains a function for looking up which template should be used (yes, you can get the page to choose one based on user selection, browser detection, entry page, etc.) and formatting two HTML chunks to be inserted at the top and bottom of each page, around the main page content.

These chunks are inserted by a response.write statement above and below the content of the normal site pages.

Uses for this kind of thing

For all sites, having the ability to change the appearance, layout, fonts, colours and pagewidth throughout the whole site by replacing one template file is a big bonus. The functionality also allows you to display the same pages using different templates: printer friendly versions, small screens, handheld versions, webTV versions, search engine pages, branding of content for different corporate clients, etc.


The template file must be static - ASP code within it will not run. In order to incorporate ASP code, you must run this in your buildpage.asp and add it into your page by replacing a custom xxxMYNEWTAGxxx you have added to you template(s).

Include files also cannot be used within your template. Again, you can include the code within these in your buildpage.asp if required.


This code is not for everyone but most developers will have some web sites where they wish they'd done it like this. It's another way of looking at things and it might just open up some possibilities you haven't thought of before.

 You may use the code and functions within this
 template sample application on any web site
 for free providing the comments, copyright
 messages and link to our site are retained.
 Queries? Can't promise we can respond to
 everything but try us!

Live Demo

Note From The Webmaster: We've stopped publishing live demos for most of our articles, but I felt the need to make an exception for this one so that you could really get a feel for how this works. So, without any further delay, here it is. There's a link at the bottom to come back to this page.

Getting the Code

You can download a zip file containing the scripts and this readme from here.

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback
The Network for Technology Professionals



Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers