Classic ASP Master Pages

By · March 27, 2010 · 6 comments

When developing websites most of them have common elements like headers, footers and navigational menus that are common throughout the site. In Classic ASP we mostly use multiple server side includes to accomplish this. I like ASP.NET master pages and this page details the technique I use to achieve something similar in Classic ASP.

My technique involves creating a master page ASP file which has all the common elements. Where ever I want content to be added I add a call to a sub routine.

Then in my content pages when I want the master page content to be added I include it at that point. I then create a sub routine for each content area and put my content inside these. You can have as many content sub routines as required but they must exist in every content page that uses that master page.

The following example shows a master page and content page with two content areas: one inside the head tag (called HeadPlaceHolder in this example) so I can easily add title and meta tags, and add JavaScript and CSS within the head tag if required; and one inside the body tag between the header and footer (called ContentPlaceHolder in this example).

Any ASP variables that are needed by more than one content area should be created outside of the sub routines.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<% Call HeadPlaceHolder() %>
<link rel="stylesheet" type="text/css" href="stylesheet.css" />
<script language="javascript" type="text/javascript" src="/java.js"></script>
<div id="header">
Logo etc etc
<div id="content">
<% Call ContentPlaceHolder() %>
<div id="footer">
Copyright etc etc


<!--#include virtual="masterpage.asp"-->

'Any ASP variables that are needed by multiple contenbt areas should be declared
'outside of the sub routines
'It's a good practice to keep your ASP script at the beginning of your pages anyway
<% Sub HeadPlaceHolder() %>

<title>My page title</title>
<meta content="My meta description" name="description" />

<% End Sub %>

<% Sub ContentPlaceHolder() %>

<p>My page content goes here</p>

<% End Sub %>
Classic ASP

Get the latest posts delivered to your inbox.

Comments (6)

# Posted by Pere · January 26, 2011

It doesn't work if you want to set dinamic content.
<% Titl = "My dinamic content, form BBDD"
Sub HeadPlaceHolder() %>

<meta content="My meta description" name="description" />

<% End Sub %>

But is a great code.
I'm fighting to find a way to change dinamically my page's Title if you have an include, that contains <head></head>, befor your content page.


# Posted by JT · April 22, 2011

Pere, move your assignment of Titl into the code block at top as suggested. This technique does work and it's great. Now I can use proper templates with classic ASP.


# Posted by Rod · May 3, 2011

Thanks so much John - exactly what I need as well.


# Posted by Pico Genkaku · November 29, 2014

Thanks for this post! I've managed to create my draft website using Classic ASP and using master pages =)


Pico Genkaku
# Posted by Mickey Cutshall · April 4, 2016

Informative suggestions . I Appreciate the analysis - Does anyone know if I might be able to grab a sample IRS W-3 example to use ?


Mickey Cutshall
# Posted by Stuart · March 15, 2017

forget that .net core. i'm going back to classic asp. this is great stuff. thanks!


Leave a Comment

All comments are moderated and rel="nofollow" is in use. Avatars are sourced from – a globally recognised avatar.

Type the numbers from the picture above

About me
John Avis ...mostly about web development and programming, with a little bit of anything else related to the Internet, computers and technology.

profile for John at Stack Overflow, Q&A for professional and enthusiast programmers

Get the latest posts delivered to your inbox. *