Forum Moderators: open

Message Too Old, No Replies

Headers and Footers in ASP

         

dvduval

5:54 pm on Apr 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've had great success with using include files in PHP to allow me to change headers and footers site wide. With the importance of link text these days, this has really paid off, because I can quickly increase the importance of a page on my site by a quick change to the footer file.

For ASP, I'm not quite as well versed. I did a search on ASP includes and tried it out, but something is not working.
I'm hoping someone can help.

Let's suppose I want to include header.asp and footer.asp in index.asp. Could someone show me the code? Would it be any different on .aspx pages?

Thanks

BlobFisk

6:04 pm on Apr 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<!--#include file="pathTo\include.file" -->

You can use file or virtual, where file is the relative path to file from ASP page; and relative is the root relative path to the file.

If you are still having problems, have a look at the pathing, and if you are still having problems a code snippet of the include call you are using may help!

<edit>Typo fix</edit>

[edited by: BlobFisk at 6:05 pm (utc) on April 10, 2003]

GaryK

6:04 pm on Apr 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<%@ Language=VBScript %>
<% Option Explicit %>

<!-- #include virtual="/html-header.asp" -->

Page content goes here....

<!-- #include virtual="/html-footer.asp" -->

The first include has everything up to where your page content starts.
The last include has everything from the end of your conent to the end of the document.
It's amazing what you can do in between.

I hope that's what you're looking for... my sample is a very stripped down version of what I use on several busy websites.

ziggystardust

6:05 pm on Apr 10, 2003 (gmt 0)

10+ Year Member



Including files is done like this:

<!--#Include file="header.asp"-->

or like this:

<%
server.execute("header.asp")
%>

//ZS

dvduval

6:13 pm on Apr 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If I have the latest server (I think it's called .net server), should I use the aspx extension...
...for the index file?
...for the header and footer files?

dvduval

6:32 pm on Apr 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The only problem I'm getting is with head tags and metatags.
If I try to use head tags, it creates a compilation error. What is the best way to add head tags to and ASP page? Do I need to use a separate include file for the head tags? Do I need one for each page?

sullen

7:01 pm on Apr 10, 2003 (gmt 0)

10+ Year Member



only use the aspx extension if your pages are coded in asp.net (which is different to ordinary asp) - the .net server can handle old-fashioned asp pages.

Don't understand why you'd want to include the <head> tags in an include file (as they'll be different on every page), but there's no reason why it shouldn't work with server.execute("page.asp").

PRNightmare

7:23 pm on Apr 10, 2003 (gmt 0)

10+ Year Member



Go ahead and place your <head> tag and generic site-wide meta content in your include or header file.

Go ahead and close with a </head> in your include or header file.

At this point, you'd think that would be the end of that, and you wouldn't be able to specify different meta content for the different pages of your site. However...

Go ahead and place content specific meta content after your include declaration. This meta content will over-ride what appears in your header/include. In other words, you can declare meta content outside of your <head></head>.

Make sense?

I do this so that, some pages where I don't specify meta content (cause it's just not really needed) get the generic title and meta. However, the pages where I need to get specific get additional meta content as needed.

This works so long as you've got the .asp or .aspx extention. I don't know about php.

dvduval

7:37 pm on Apr 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This works:

<%@ Language=VBScript %>
<% Option Explicit %>
<!-- #include virtual="/header.asp" -->
<title>ASP Test</title>
Page content goes here....

<!-- #include virtual="/footer.asp" -->

This does not work:


<title>ASP Test</title>
<%@ Language=VBScript %>
<% Option Explicit %>
<!-- #include virtual="/header.asp" -->
<title>ASP Test</title>
Page content goes here....

<!-- #include virtual="/footer.asp" -->


Forum note: strange the second code tag enclosure results in smaller text.

I tried moving around the title tag and also enclosing it in head tags, but nothing worked. What gives?

aspdaddy

9:14 pm on Apr 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think option explicit has to come first.

You can use static & dynamic meta, in the head with 2 headers - (put your option explicit/doctype in header1)

<!-- #include virtual=/header1.asp -->
<static title ...
<static metas ...
<!-- #include virtual=/header2.asp -->
Content here
<!-- #include virtual=/footer.asp -->

HyperGeek

9:28 pm on Apr 10, 2003 (gmt 0)

10+ Year Member



This code will work perfectly for you:

<%@LANGUAGE="VBScript"%>
<%Option Explicit%>
<%
'(This makes sure that the user receives a fresh version of the page)
Response.Expires="-100"
%>
<HTML>
<HEAD>
<BASE HREF="http://www.mydomain.com">
</HEAD>
<BODY>
<!--#include virtual="/include/header.asp" -->
<TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0" WIDTH="100%">
<TR>
<TD></TD>
</TR>
</TABLE>
<!--#include virtual="/include/footer.asp" -->
</BODY>
</HTML>

---

Make a separate directory for your include files named "include".
(You'll be glad you did int he long run.)

As a rule of thumb, do this with all the separate "elements" of your web site. Images go into an image dir, Flash in a flash dir, includes..., ect.

Now set a base URL within your <HEAD> tags. Leave out the last "/". Now every image or link within your site needs to be like this...

<IMG SRC="/images/image.gif" WIDTH="##" HEIGHT="##" BORDER="0" ALT="">

<A HREF="/page.asp">This is my link!</A>

...with a preceeding forward slash.

Things will now be more organized and easier to maintain in the future...especially as it expands in content.