Welcome Guest!
Create Account | Login
Locator+ Code:

Search:
FTPOnline
Channels Conferences Resources Hot Topics Partner Sites Magazines About FTP RSS 2.0 Feed

Free Trial Issue of Visual Studio Magazine

email article
printer friendly
get the code

Maintain Consistency With ASP.NET Templates
Build page templates quickly and easily with the XML-based ASP.NET template framework.
by Dan Wahlin

Posted October 9, 2003

ADVERTISEMENT

Templates provide an excellent way to maintain a consistent look and feel across a Web site. However, version 1 of ASP.NET doesn't natively support the concept of templates. Fortunately, this isn't a major stumbling block because the .NET platform provides a robust object-oriented environment you can leverage to create custom template solutions. You can create many different ASP.NET template solutions that leverage the concept of inheritance in .NET.

I was tasked recently with creating an ASP.NET template framework that was flexible and usable for programmers and non-programmers alike. I researched several existing template frameworks and found that each had definite pros (and some had a few cons) depending upon the skill level of the developer using them. Here are a few of the template solutions I came across (in no particular order):

  • "Page Templates Revisited" by Jonathan Goodyear
  • "Page Templates"
  • "ASP.NET Page Templates: Using Inheritance" by Peter Provost
  • Wilson DotNet.com
  • "Creating a Page Template by inheriting from the System.Web.Page class" by Ryan Trudelle-Schwarz
  • "Master Pages"

From a programmer's perspective, you can use many of these template concepts (as well as others not listed) because they offer robust solutions. However, from a non-programmer's perspective (think of a "Web publisher" who only knows the basics of HTML), many of these would be tough to comprehend, making it difficult to integrate a single Web page into a Web site's template framework.

As a result of needing to support a variety of skill levels, the ASP.NET template framework I created relies upon XML to mark up the structure of a given Web site. This allows you to generate the template structure quickly and easily without having to worry about embedding HTML code into .NET classes and recompiling (and redeploying) whenever the template changes. It also prevents unnecessary nesting of Web server controls within user controls (or user controls within user controls). Take a look at this sample XML template; you'll see that it consists mainly of standard HTML tags:

<html xmlns:template="http://www.xmlforasp.net/templates">
  <head>
    <title>XML for ASP.NET Developers</title>
    <script language="javascript" 
      src="Scripts/scripts.js"> </script>
    <link rel="stylesheet" type="text/css" 
      href="Style/style.css" />
  </head>
  <body bgcolor="#ffffff" topmargin="0" leftmargin="0">
    <form id="frmPageForm">
        <table class="tableBorders" border="0" 
          width="759" cellpadding="0" cellspacing="0" ID="Table1">
          <tr>
            <td colspan="2" align="left" valign="top">
              <template:UserControl id="ucHeader" 
                src="UserControls/Header.ascx" />
            </td>
          </tr>
          <tr>
            <td align="left" valign="top" width="164"
              bgcolor="#02027a">
              <template:UserControl id="ucNavigation" 
                src="UserControls/Navigation.ascx" />
              <template:UserControl id="ucPartners" 
                src="UserControls/Partners.ascx" />
            </td>
            <td align="center" valign="top" width="595">
              <template:PlaceHolder id="Content" />
            </td>
          </tr>
          <tr>
            <td colspan="2">
              <template:UserControl id="ucFooter" 
                src="UserControls/Footer.ascx" />
            </td>
          </tr>
        </table>
    </form>
  </body>
</html>



Back to top














Java Pro | Visual Studio Magazine | Windows Server System Magazine
.NET Magazine | Enterprise Architect | XML & Web Services Magazine
VSLive! | Thunder Lizard Events | Discussions | Newsletters | FTP Home