ASP #include
#include directive
By using the #include directive, you can insert the contents of another ASP file into this ASP file before the server executes the ASP file. The
#include directive is used to create functions, headers, footers, or other elements that need to be reused on multiple pages.
How to use the #include directive
Here is a file named "mypage.asp":
<html>
<body>
<h3>Words of Wisdom:</h3>
<p><!--#include file="wisdom.inc"- -></p>
<h3>The time is:</h3>
<p><!--#include file="time.inc"-->< ;/p>
</body>
</html>
This is the "wisdom.inc" file:
the number of entities required to explain anything."
This is the "time.inc" file:
Response.Write(Time)
%>
If you view the source code in a browser, it will look like this:
<html>
<body>
<h3>Words of Wisdom:</h3>
<p>"One should never increase, beyond what is necessary,
the number of entities required to explain anything."</p>
<h3>The time is:</h3>
<p>11:33:42 AM</p>
</body>
</html>
##Syntax for referencing filesIf you need to use ASP To reference files in the page, please put the #include directive in the comment tag:
or
<!--#include file ="somefilename"-->
Please note that the path of the referenced file (headersheader.inc) is relative to the referencing file. If the file containing the #include statement is not in the html directory, this statement will not take effect.
Tips and Notes
In the above section, we have used ".inc" as the file extension for the referenced file. Please note: If the user attempts to browse the INC file directly, the contents of this file will be displayed. If the content in your referenced file contains confidential information or information that you do not want any user to see, it is better to use ".asp" as the extension. The source code in an ASP file is compiled and invisible. Referenced files can also reference other files, and an ASP file can reference the same file multiple times.
Important: The referenced file will be processed and inserted before the script is executed. The following script cannot be executed because ASP executes the #include directive before assigning a value to the variable:
fname="header.inc"
%>
<!--#include file="<%fname%>"-->
You cannot include file references between script delimiters. The following script cannot be executed:
For i = 1 To n
<!--#include file="count.inc"-->
Next
%>
But this script can be executed:
< !--#include file="count.inc" -->
<% Next %>