9:16 am Wednesday, August 20, 2008


  Navigation
  Help?
Contact Aaron for all inquiries.
 

  News

ASP Inline Calendar 3.9 Beta 1
ASP Games
ASP Inline Corporate Calendar 3.8 BETA 1 Demo
Calendar Updates
 

A Better World By Design
 
 
AaronOutpost : ASP / Web Design / Include Files Tutorial For ASP

Include Files For ASP
By: Aaron B. Copyright AaronOutpost.com

Back to Web Design Tutorials          Back to ASP Tutorials

Though this tutorial may be for including files with ASP, most languages support the option to include files. Just the code is slightly different.

Include files is a great feature and will hopefully become a great resource to yourself. I use include files in all of my application as well as my website. Instead of re-entering the same code over and over again you can create one file and include it on other pages. Such as a page header and footer. You will notice on AaronOutpost.com there is the same header and footer on every page. I used an include file to load header.asp and footer.asp which are in my virtual directory. So how can you do it?

Include file command only works on .ASP files but it is actually entered outside the script tags <% %>.

<!-- This script will fail -->
<%

If view <> "print" Then

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

End If

%>


<!-- This script will work -->

<%

If view <> "print" Then %>

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

<% End If %>

 

The virtual and file keywords indicate the type of path you are using to include the file, and filename is the path and file name of the file you want to include.

Included files do not require a special file name extension; however, it is considered good programming practice to give included files an .inc extension to distinguish them from other types of files. I however do not do this because it makes for easier editing if all files have the same extension .asp. I name my include files inc_filename.asp

 

Using the Virtual Keyword

This uses the virtual directory as a base. I use this for the include files that you see on the left and right side of AaronOutpost.com. Since you will be browsing multiple directories on the website, I needed to have the files link to it's physical place on the server. Let's say you have a my calendar on your website. It would reside in Calendar. You want to include the mini calendar on all of the pages so you would use the following.

 

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

 

Using the File Keyword

Now lets say you want to use the relative directory. Maybe you want the header to change depending on what directory you are in.

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

Now you can still call files from sub directories using the file command.

<!-- #include file ="includes/header.asp" -->

 

So create a header.asp and a footer.asp that contains an html layout for your website. Your include files can also contain ASP script. In the final example I include AaronOutpost.com Header and Footer files.
 

 


AaronOutpost : ASP / Web Design / Include Files Tutorial For ASP

Aaron Outpost West Virginia, USA A Mark of _-Squire-_ Creations Inc.  CopyrightŠ 2005 All Rights Reserved