Click to See Complete Forum and Search --> : Call ASP pages when other webpages load
ka4at
04-04-2007, 02:13 PM
Hello all
I have just started learning ASP and need some help with the following issue
If I have for example six webpages (asp or html ) i.e 1, 2, 3, 4, 5, 6 and all of them have a menu on the left which requires updating quite often ( no database just special offer images and normal menu list) is it possible to create a menu file ( i.e another webpage menu.asp / html ) which the other six webpages display when they load instead of changing all of them one by one
So basically When the menu needs changing all I do is change the menu.asp / html webpage and all the other pages should change automatically as they all load menu.asp when they load as well
Any help would be much appericated :)
lmf232s
04-04-2007, 04:05 PM
Absolutely!
They are called server side includes.
You place a bit of text on your page that looks like this
<!--#include virtual="Include/menu.asp"-->
Where Include is the directory on the root of the web site.
In your menu.asp page you might have code like this (it can be anything, html, javascript, vbscript, etc)
<div id="Test01">
This is some text
</div>
Then say you have another page Home.asp
In your home asp page it might look like this
Home.asp
<!--#include virtual="Include/Header.asp"-->
<!--#include virtual="Include/menu.asp"-->
'Page Content Goes Here
This is your main content
<!--#include virtual="Include/Footer.asp"-->
When this page executes it will retrieve the header.asp, menu.asp and footer.asp pages and load that content in the Home.asp page.
The beauty of using server side includes is exactly what your after. Reusable code and maintenance. If you need to change your header you change 1 file, same with the footer and the menu.
Do a google search on Server Side Includes and youll get tons of hits.
Hope that helps.
buntine
04-04-2007, 08:14 PM
Note that alot of servers disable virtual includes (relative paths) as a security measure. It is an understandable, but intensely annoying practise.
The alternative is to use explicit paths with the following:
<!-- #include file="inc_header.asp" -->
Also, make sure you always use the .asp file extension on your includes. Microsoft initially recommended you use the .inc file extension, but this is VERY bad practise as those files can be downloaded by any user without them being parsed, thus raw source can be viewed.
I normally prefix my include files with "inc_", so they are easily identifyable in larger projects. Another option is to create an "includes" directory.
Also prefixing any variables used within the include files with "inc_" may also help to reduce the possibility of redimensioning variables or the headache of tihnking of appropriate variable names when the most obvious is already used in an include!!
Andrew Buntine.
ka4at
04-10-2007, 04:50 AM
Hello
Many thanks for your help
Much appericated:)