AbstractNearly every web site has some type of common layout used for each Page. Classic ASP allowed developers to use Include files to encapsulate reuse. ASP.NET provides many new and better techniques to accomplish the same. This article provides a brief introduction to Page Templates in ASP.NET, which generally refers to the use of inheritance with a base Page class.

Page Templates: Introduction

Overview

Nearly every web site has some type of common layout used for each Page. Classic ASP allowed developers to use Include files to encapsulate reuse. ASP.NET provides many new and better techniques to accomplish the same. This article provides a brief introduction to Page Templates in ASP.NET, which generally refers to the use of inheritance with a base Page class.

User Controls

The easiest new Page Template method in ASP.NET involves User Controls. User Controls are mini-Pages, or Pagelets, created almost just like Pages. Most developers find it easy to setup the regions common to the whole site into User Controls, like a Header and Footer, possibly a Menu and SideBar. This Page Template technique simply allows one to automate it on each Page, instead of registering and using these User Controls manually each time. It was originally suggested by some to use a PlaceHolder for the Content, but further work has demonstrated the Content is best left on each Page. See the code download or my Page Template Generator for the full examples.

Direct Render

The best performing Page Template method in ASP.NET avoids all controls, since each control is about 30% slower than the equivalent static html. Note that ASP.NET is still usually a good deal faster than Classic ASP, due to compiling and better caching, so most developers don't bother here, since this technique does have the reputation of being harder to utilize. The difference is that the common layout must be directly coded as html, without using the nice designer (i.e. control) features of GUI Designers, although a quick look at the code and you realize its not that different. See the code download or my Page Template Generator for the full examples.

Other Resources

This article is meant to just be a brief introduction to Page Templates. The following comprehensive list of articles/tools, by myself and others, will provide the means for you to take and research this subject further.

Author Bio

Paul Wilson is a software architect in Atlanta, currently with PRG-Schultz. He specializes in Microsoft technologies, including .NET, C#, ASP, SQL, COM+, and VB. His WilsonWebForm Control allows Multiple Forms and Non-PostBack Forms in ASP.NET. He is a Microsoft MVP in ASP.NET and is also recognized as an ASPInsider. He is a moderator on Microsoft's ASP.NET Forums, as well as one of the top posters. He is holds the MCSD, MCAD, MCDBA, and MCSE certifications. Please visit his website, www.WilsonDotNet.com, or email him at Paul@WilsonDotNet.com.