By Jeremy J.
I've got a suggestion for a tip I've picked up when making ASP/SQL pages.
I often find my self using a similar design over a large number of pages, and I want to have a header and a footer. I know this could be set up with two lines:
<!--#include file="header.inc"--> and
but for me that means editing more files, and doesn't allow easily to see both files at once, for example if I made a large change to the site design. Also, on some pages I want to include a small form that updates something in a database using SQL, and depending on the results of that, possibly forward the user to another page. For example - I have a logon page for an admin area called logon.asp. The user enters their username on the page and the actual checking of the user is done on that page:
However, there can be some problems doing things like this - if the checking part needs to look something up on a database, then I need to specifically set up the database connection string beforehand - if it was in the header, then I'd have to do the checking after the header was shown, and then I couldn't use the forwarding method. If this is the same string as I need for several pages, and it may change, then I need to include a third file called something like database.inc and include that at the top of every page. Help! - 3 include files.
However, I discovered a nifty way of only using one include file, and it
certainly solves all my problems. The file is called
looks like this:
Now, creating new database-enabled pages is very simple - I simply write them like this:
Simple, eh? Also - if I wanted to put any code at the top of the page, I
can put it between the
<!--#include line and the
<% Call header line.
Note, I also used a variable to change the title of the page - other
variables could be used for similar purposes.
Now, if I need to change and of the information on pages, I simply need to
includes.asp file - where everything is in one place.
Great site guys - keep up the good work! I'll let you know if I think of any other useful things I've learnt in ASP/SQL, mostly from working on the site at http://www.planetquake.com/airquake2/.
|Return to user tips...|