Setting up your own ASP development templates

Source: Internet
Author: User
Tags html comment keywords list password protection
Setting up your own ASP development templates
By nannette Thacker-05/01/1999

After you 've been working with ASP development for a while, you will find that there are standard things which you include in every web page. to avoid using "Frankenstein cut-and-paste" code, you shocould setup a template which CILS every standard page element. this template can be then be used for every new page you create. if designed properly, you will never have to edit more than one page when a change has to be made to these standard elements. for instance...

Use header and footer functions instead of Cascading Style Sheets (CSS)

Cascading Style Sheets are great, but they are browser dependent. to avoid alienating the majority of browser users from your web site, you can setup every page as. ASP page (not an HTML page) and at the top of the each page include a header file and at the bottom of each page include a footer file. when new elements need added or old elements removed from the header or footer (links to other pages or new images, perhaps), the change only needs to be made in one place.

All page elements, such as header, footer, tablehead, tablefoot, et CENAMES, can be stored in a subdirectory such as "/pageelements" or in your "/include" directory.

My ASP template used with this site

Following is the source code for my asp template used with this site:

<% @ Language = VBScript %> <! -- # Include virtual = "/articles/include/pagetop. ASP "--> <% '------------------------------------------------------ 'template. ASP 'page template for the site. ''created 5/1/1999 by nannette Thacker ''into dim strpage, strpagedescriptionstrpage =" template "strpagedescription =" ASP advice: "%> <HTML>  

Now I'll break the template down into its parts and describe what each include file does:

<! -- # Include virtual = "/articles/include/pagetop. asp" -->

My pagetop. asp file is quite simple now. It simply consists:

 
<% Option explicit %>

Option explicit forces me to dim all of my variables. See my article on ASP naming conventions for details.

The pagetop. ASP file can also include site password protection and other coding as needed. but the great thing is, if you put this include at the top of all of your. ASP pages, later on when you wish to include something at the top of the every page, you'll be ready to go!

 
<% '-------------------------------------------------- 'Template. asp' page template for the site. ''created 5/1/1999 by nannette Thacker' then '------------------------------------------------------

Then, of course, you'll wish to document your code. you may wish to do this in VBScript so it is hidden and processed server side, or you may wish to include comments and copyright information client side with HTML comments instead. or perhaps you'll wish to use both kinds of comments. either way, be sure to comment your code.

 
Dim strpage, strpagedescriptionstrpage = "template" strpagedescription = "ASP advice:" %>

I like to create a strpage variable which contains the actual file name of the page. this may come in handy later on the page when you call something like a header, footer, or link. that way, you can customize your header, footer, links, validation functions, or whatever, dependent upon the name of the current page you are on. for instance, I have a javascript field validation function which is similar on multiple pages. I can use a VBScript if/else statement inside the JavaScript to include certain field validation elements dependent upon the name of the current page.

The strpagedescription variable is used in the meta tag. it allows you to customize the page description. for instance, in the include file shown below, the meta tag prints the strpagedescription variable as part of the description. this allows you to use the same description on every single page, yet also customize the description as well.

<! -- # Include virtual = "/articles/include/meta. asp" -->

In the below block of code from the meta. ASP file, the name of. ASP page is printed in an HTML comment at the top of each page. you can easily tell the file name by viewing the source code.

<% 'Include the name of the page in the HTML code. When View Source from browser 'can easily find originating page if viewing from within a frame. response. Write "<! -- "& Strpage &". ASP --> "'------------------------------------------------------'/include/meta. ASP 'sets up the default meta tags for each page. 'The meta description can have additional text added' to it as defined in the calling page via the variable' "strpagedescription ". ''created 5/1/1999 by nannette Thacker '-------------------------------------------------------- %> <meta name = "Description" content = "<% response. write strpagedescription %> Web application development advice. "> <meta name =" keywords "content =" ASP, Active Server Pages, web, programming, ASP advice, Internet, Visual InterDev, VBScript, JavaScript, HTML, web development, oracle, ms SQL Server, database, ASP Warriors "> <meta name =" resource-type "content =" document "> <meta name =" distribution "content =" Global "> <meta name =" Copyright "content = "Shining Star Services"> <meta name = "author" content = "nannette Thacker"> <meta name = "generator" content> <meta name = "Robots" content =" all ">

You can easily create page variables for the keywords list as well. Then add the keywords variable at the beginning of your keywords list to customize a meta tag for each page.

 
<Title> Asp advice </title>  

Then is the title, which you will alter for each page you create. I like to include my body tag in a body. ASP page to be writable ded in each page, rather than using Cascading Style Sheets, since I don't want to exclude those who haven't updated their browsers. in my body. ASP page I setup my default font and link colors.

 
<Body background = "/images/bg.gif" link = "# ff8000" vlink = "# daa520" alink = "# ff8000" text = "#000000"> <basefont size =" 3 ">

Now if I ever wish to change my basefont size, my background, or my link colors, I can change them in one place instead of having to edit every single page.

The rest of the template page contains des a header. asp file, which prints my logo, and sets up my table, including the text in my left table.

 
<! -- # Include virtual = "/articles/include/header. asp" --> <br>  

It also includes my code for the head text that falls at the top of the each page, and my footer, which ends the table.

The rule is, anything that is repeated on multiple pages shocould be in your template. And anything which is a large amount of text or code, shocould be in an include file.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.