Classic ASP Master Pages

John Avis by | March 27, 2010 | Classic ASP

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.
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.

masperpage.asp

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<% Call HeadPlaceHolder() %>
<link rel="stylesheet" type="text/css" href="stylesheet.css" />
<script language="javascript" type="text/javascript" src="/java.js"></script>
</head>
<body>
<div id="header">
Logo etc etc
</div>
<div id="content">
<% Call ContentPlaceHolder() %>
</div>
<div id="footer">
Copyright etc etc
</div>
</body>
</html>

content-page.asp


<!--#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 %>

Related Posts

Classic ASP

Sending email using Amazon SES with Classic ASP

by John Avis | March 21, 2017

I recently needed to change a client's website to send emails using Amazon SES and encountered a few issues.


Classic ASP

Classic ASP class constructors with parameters

by John Avis | June 8, 2016

Although probably no one cares about Classic ASP, except those who still need to support it, I was refreshing my memory today on how to use classes in Classic ASP and found a couple of options for simulating constructors with parameters.


Classic ASP

Classic ASP cookie with no name hacking attack causing error 80004005

by John Avis | July 31, 2015

As of July 2015, many of my Classic ASP websites have started logging strange errors, either 80004005 or not reporting any error code at all.

Comments

Pere

by Pere | January 26, 2011

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

<title><%=Titl%></title>
<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.

Reply

JT

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.

Reply

Rod

by Rod | May 3, 2011

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

Reply

Pico Genkaku

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 =)

Reply

Mickey Cutshall

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 ?

Reply

Stuart

by Stuart | March 15, 2017

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

Reply

Leave a Comment
Tags
ASP.NET Html Forms ASP.NET MVC ASP.NET Web Forms ASP.NET Web Pages Bootstrap C# Classic ASP Cool Websites Databases eBay and PayPal Electrical Repairs General Hardware HTML/CSS Jquery/Javascript Media Center Mobile Phones Responsive Web Design SEO and Social Networking Web Design Web Development Web Security web+db Website Hosting Windows XP

About me

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

Subscribe

Get the latest posts delivered to your inbox.