ASP/.NET Web Hosting
* 3 Months FREE *
CLICK HERE!
 CoverYourASP --> Object oriented ASP --> Part 2: The Page Classes

Free membership

Join in the fun! Sign in
Member Services

Site navigation
Download the entire site!
Search my articles
Free Magazines
Browse the directory

Send me feedback
Buy my boxer shorts

Recommend this page
Printer-friendly page

Resources I recommend
Link to my site
Advertising slashed!
About your privacy
Legal stuff
Site statistics
148 active users
2909 visitors today
2840 pages today
(only part of today)
ASP.NET Showcase
ASP.NET Graph and Chart Component with FREE developer version

ASP.NET Shopping Cart and E-commerce Control with FREE trial download

ASP.NET Web Hosting with free month and setup

$15 Domain Name Registration from .DNR.
As seen on these sites
Special thanks go to the sites that support me by publishing my articles.
See more

CoverYourASP
Copyright © 1999-2008 James Shaw.
All rights reserved.

ASP.NET Blog
ASPRSS
ShawThing

Now open source with SourceForge!

Defining the classes

Defining a class called Page in JavaScript is as easy as creating a function of that name as a constructor. Take a moment to understand the code below, taken from utils/PageCounter.asp, and it will open up a whole new world!

(For a full description of JavaScript objects, read Microsoft's documentation.

<%
// create a single page object
var oPage = new Page ( );

// ============================================
// Page object constructor
// ============================================
function Page ( )
{
   // a page contains a <head> and a <body>
   this.Head = new Head ( );
   this.Body = new Body ( );
   this.Out = PageOut;
}

// ============================================
// Body object constructor
// ============================================
function Body ( )
{
   // a body contains a <Header> and a <Footer>
   this.Header = new Header ( );
   this.Footer = new Footer ( );
   this.Out = BodyOut;
}

// ============================================
// Head object constructor
// ============================================
function Head ( )
{
   this.Out = HeadOut;
}

// ============================================
// Header object constructor
// ============================================
function Header ( )
{
   this.Out = HeaderOut;
}

// ============================================
// Footer object constructor
// ============================================
function Footer ( )
{
   this.Out = FooterOut;
}
%>

Here you can see how the classes and the hierarchy are defined. Each class has just one common method - they all have an Out() function that will output the relevant html.

In each case the member Out is assigned to a function name defined elsewhere. Let's look at the first example, PageOut():

function PageOut ( )
{
   Out ( '<html>' );

      // output <head>
      this.Head.Out ( );

      // output <body>
      this.Body.Out ( );

   Out ( '</html>' );
}

Notice how the <html> tags are in the same function? This is the encapsulation that I wanted from these classes - the function does what it knows best, and no more. It knows that a <html> needs a </html>, then tells Head and Body to do their thing.

Part 3: A sample page...

Featured sponsor
My favorite resources

Selling products online - read how James does it now



I share my content

Supporting ASPRSS

Do you need a quick and easy way to link to my articles? All the information you need is published with ASPRSS...

CoverYourASP Mugs, T-shirts, caps - even Boxer shorts...
I don't make a penny from these, but they're a lot of fun! Don't you need a new mouse mat?


New Proposal Kit Professional 5.1
Brand yourself as a top professional: create quotes and amazing proposals and get many legal documents free!

The latter saved me 3 times the purchase price on the first day I owned it!