ASP 101 - Active Server Pages 101 - Web03
The Place ASP Developers Go!

Please visit our partners

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates

ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash

 Top ASP 101 Stories Top ASP 101 Stories
Connections, Commands, And Procedures
What is ASP?
VBScript Classes: Part 1 of N

(<OBJECT> vs. Server.CreateObject())
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates

Dyno default.asp, ASP and Text Files

The homeboy. So now most all of the default.asp homepage has been assembled by opening simple text files and filling the areas with the text file content. Suddenly this whole page can be left alone for long periods of time. If you make a mistake in the text file, this normally won't affect operations at all. Your customers may think twice...oooops.

Ok, there's no browser checking, just a little code for noframes, this is very basic. Most developers of websites must be concerned with the user viewpoint and supporting the content for a variety of browsers is a fairly common procedure. There are two strategies for this, send javascript to the client and document.write at the places on a page where browser detection is needed; or, detect from the HTTP headers what browser is making the request and send a static page.

What the overall design intends to do has a great influence on the presentation of the page. Design elements in this case were composed of frames. The text file system can also produce composite single pages with this same source material. This would avoid the frames issue entirely by producing a page with tables instead.

To begin, the code for the banner is simple, just some font tags.

<div align="center"><b><font face="Book Antiqua" size=4><font size=6>O</font>nline<font size=6>A</font>rticles and <font size=6>P</font>hotography</font></b></div>

In this example the main page is constructed in pieces as before. The graphic used is the ASP ad rotator component, the text is in a separate text file with the footer table also a separate file, and all this will now be used to produce a set of tables to replicate the look of frames. Using only tables allows the content to be seen by almost any browser, which is best for a homepage, as is plain html. Using even javascript runs into trouble for a wide audience, yet that doesn't apply to LAN's as much, where the scripting can perform many business rules without server hits; something to always keep in mind.

The code

Creating a default.asp
In this case, typical code to create the frames version of the page:

<!-- DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 3.2 Final//EN'-->
<title>Outdoor Photography and Other Interests</title>
<frameset rows="44,*" frameborder="yes" framespacing="1" border="1">
<frame name="banner" src="banner_01.asp" marginwidth="3" marginheight="3" scrolling="auto" frameborder="no">
<frameset cols="106,*">
<frame name="nav" src="nav_01.asp" marginwidth="3" marginheight="2"
scrolling="auto" frameborder="no">

<frame name="main" src="main_01.asp" marginwidth="6" marginheight="6"

Your browser does not support frames so won't be able to view this website, please download an up to date browser as no text-only navigation is available.
Examining the main page, it has a content text file, then the ad rotator and finally the footer is added from another text file.
dim main_obj, main_file, main_content
set obj_ad = server.createobject("Scripting.FileSystemObject")
set ad_file = obj_ad.opentextfile("D:/webshare/wwwroot/asp/examples/main_content.txt")
on error resume next
main_content = ad_file.readall

This has the file main_content.txt open and moved into the variable main_content. Next I'll insert the ad rotator which is supported by two other test files!! These control what images are displayed and the URL's for links. The first of these is called the schedule file as it defines the amount of relative time each ad gets, as well as the graphic size and sources:

REDIRECT ad_urls.asp
Online articles and photography
Other online articles and photography
This simple two entry example uses the 96x64 pixel with border image to flip, there is no text.
dim mainfile, fileObj
set fileObj = createobject("Scripting.FileSystemObject")
Did the object get created? If yes, open the file:

if isobject(fileObj) then
set mainfile = fileObj.opentextfile("D:\webshare\wwwroot\asp\main_content.txt")
As before, an error can occur here if the file isn't found, or can't be opened by the system so having an on error statement is important to keep the client application from hanging. To handle this error one could use a default list in memory which was included at runtime, or hard-coding URL's which are used on file system errors (404's). The error code to create a default dictionary would look something like:
on error resume next
dicObj.item("default.htm") = "Industrial Design and Other Interests"
dicObj.item("products.htm") = "An Interesting Array of Products"
dicObj.item("prices.htm") = "Current Pricing"
dicObj.item("technical.htm") = "Technical Details of All Products"
dicObj.item("white_papers.htm") = "White Papers Outlining Features and Scope"
dicObj.item("support.htm") = "Contact Our Friendly Support Crew"
dicObj.item("archive.htm") = "Dive Into the Archives for Facts"

The code now has main_content.txt open in read-only mode if there wasn't an error. To read a line you code a statement:

while not mainfile.atendofline
dim main
main = mainfile.readline

Again we need to separate this string which is separated by a comma. Instr() is used to find a place, and mid() is used to retrieve it. With two variables, two mid()'s will retreive the key and value.
dim comma, start, length, aurl, atopic
start = instr(main, comma)
length = len(main)
aurl = mid(1, start - 1)
atopic = mid(start+1,length)
Next, main_01.asp uses the ad rotator (which only rotates on refresh).
dim obj_ads, ad_border, ad_click, ad_content2
set obj_ads = server.createobject("MSWC.AdRotator")
obj_ads.Border = (1)
obj_ads.Clickable = (True)
obj_ads.TargetFrame = ("_top")
ad_content2 = obj_ads.GetAdvertisement("ad_content.txt")
For redirecting the urls, this coding is in the url file used by the rotator.
dim gothere
gothere = request.querystring("url")
Then there is the footer, stored from another text file of course.

dim ad_obj, ad_file, ad_content
set obj_ad = server.createobject("Scripting.FileSystemObject")
set ad_file = obj_ad.opentextfile("D:/webshare/wwwroot/asp/examples/footer_01.txt")
on error resume next
ad_content = ad_file.readall
It looks like all the pieces are ready to build the dynamic part of the coding now. I'll have to create a master table and plot layouts to get a similar design to the frames version. This is nested tables, with the choice of either specifying percentages or absolute size in pixels as the usual methods of doing this. The outer table is a 100% wrapper with the first row the banner. Absolute pixels are used to control the look, percentages would be fine for many designs but here it looks weird when the nav bar resizes.
<table width=640 border=1 cellspacing=2 cellpadding=6>
<tr><td colspan=2 align="center" valign="middle"
<tr><td width=48 rowspan=3 align="center" valign="top" bgcolor="White">nav</td><td width=592>main</td></tr>
Seems to look about right. So, to assemble the page dynamically, these pieces will flow together as below.
<%@ Language="VBScript"%>
<% response.buffer = True%>
response.write("<!-- DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 3.2 Final//EN'-->")
response.write("<head><title>Website Navigation Page</title>")
response.write("<font face='verdana,arial,helvetica' size=2>")
response.write("<table width=640 border=1 cellspacing=0 cellpadding=1>")

dim abanner, bannertext, fileObj
set fileObj = createobject("Scripting.FileSystemObject")
if isobject(fileObj) then
set abanner = fileObj.opentextfile("D:\webshare\wwwroot\asp\examples\banner.txt")
bannertext = abanner.readall
end if
response.write("<tr><td border=1 colspan=2 align=center valign=middle bgcolor=ffffff>" & bannertext & "</td></tr>")
set fileObj = nothing
response.write("<tr><td width=48 rowspan=3 align=center valign=top bgcolor=ffffff>")
dim objfile, navfile, navout
set objfile = createobject("Scripting.FileSystemObject")
if isobject(objfile) then
set navfile = objfile.opentextfile("D:\webshare\wwwroot\asp\examples\nav.txt")
end if
while not navfile.atendofline
dim nav
nav = navfile.readline
navout = navout & "<tr><td bgcolor=ccffcc height=24>" & nav & "</td></tr>"
navtable = "<table>" & navout & "</table>"
response.write(navtable & "</td><td width=592>")
dim main_obj, main_file, main_content
set main_obj = server.createobject("Scripting.FileSystemObject")
set main_file = main_obj.opentextfile("D:/webshare/wwwroot/asp/examples/main_content.txt")
main_content = main_file.readall

dim obj_ads, ad_border, ad_click, ad_content
set obj_ads = server.createobject("MSWC.AdRotator")
obj_ads.Border = (1)
obj_ads.Clickable = (True)
obj_ads.TargetFrame = ("_top")
ad_content = obj_ads.GetAdvertisement("ad_content.txt")

dim foot_obj, footer_file, footer
set foot_obj = server.createobject("Scripting.FileSystemObject")
set footer_file = foot_obj.opentextfile("D:/webshare/wwwroot/asp/examples/footer_01.txt")
footer = footer_file.readall

mainout = "<table><tr><td>" & main_content & "</td></tr><tr><td>" & ad_content & "</td></tr><tr><td>" & footer & "</td></tr></table>"
set main_obj = nothing
set foot_obj = nothing
set objfile = nothing

What this code does
It creates an entire homepage using the file system object which allows the data to be changed without changing the code for the page. It takes souce material from this variety of files to construct the page and does this without using frames. This page is viewable by most browsers, containing only tables as a feature which may not display in older browsers. This technique is very similar to using databases without the connection overhead versus the file system which is integrated directly into the operating system's I/O api's. The next idea will be how this maps directly to using a database and tables, first using the Dictionary object for rudimentary sorts and compares (still powerful for many tasks) followed by articles on mapping directly into databases and sql queries.


Double quotes separated from single quotes for clarity, don't do this !
Previous versions of VBScript are CaseSensitive, this is written for the latest version.
Development Test System: Windows98, PentiumII 200MHz 128Mb
Personal Web Server 4.0 (IIS4), SQL7b3, Personal Oracle, Sybase

Author: T.Mallard, Seattle, WA
©Copyright 1999 Thomas Mallard, USA


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback



Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers