Recommended: ASP 3.0 Advanced Programming (46) Table 10-5 HTML elements that support data binding can update data. Can table binding be displayed as HTML? A href cannot be APPLET PARAM can be MARAM can be MATTON innerText
The #include command is used to create functions, headers, footers or other elements that need to be reused on multiple pages.
#include command
By using the #include command, we can insert another ASP file into the file before the server executes it. The #include command is used to create functions, headers, footers or other elements that need to be reused on multiple pages.
How to use the #include command
Here is a file called mypage.asp:
| The following is the quoted content: <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:
One should never increase, beyond what is necessary,
the number of entities required to explain anything.
This is the time.inc file:
| The following is the quoted content: <% Response.Write(Time) %> |
The source code you view in the browser should look like this:
| The following is the quoted content: <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 of Included File:
To reference files in ASP, place the #include command in the comment tag:
| The following is the quoted content: <!--#include virtual=somefilename--> |
or:
| The following is the quoted content: <!--#include file =somefilename--> |
Keywords Virtual
The keyword virtual indicates the path located in the virtual directory.
If the name header.inc is located in a virtual directory named /html, the following line of code will insert the contents of the file header.inc:
| The following is the quoted content: <!-- #include virtual =/html/header.inc --> |
Keyword File
The keyword File can indicate a relative path. The relative path starts in the directory containing the referenced file.
Assuming that a file is located in the subfolder headers of the html folder, the following code can refer to the contents of the header.inc file:
| The following is the quoted content: <!-- #include file =headers/header.inc --> |
Note: The path to the referenced file is relative to the referenced file. If the file containing the #include declaration is not in the html directory, this declaration will not take effect.
You can also use the keyword file and syntax (../) to reference files in the previous directory.
Tips and comments
In the above section, we use .inc as the suffix of the referenced file. Note: If a user tries to browse an INC file directly, the contents in this file will be exposed. If the content in the referenced file involves confidentiality, it is best to use the asp suffix. The source code in the ASP file is invisible after being compiled. The referenced file can also refer to other files, and the ASP file can refer to the same file multiple times.
Important: The referenced files will be processed and inserted before the script is executed.
The following code cannot be executed because ASP executes the #include command before assigning values to variables:
| The following is the quoted content: <% fname=header.inc %> <!--#include file=<%=fname%>--> |
You cannot include file references between script delimiters:
The following is the quoted content: <% For i = 1 Ton <!--#include file=count.inc--> Next %> |
But this script works:
| The following is the quoted content: <% For i = 1 to n %> <!--#include file=count.inc --> <% Next %> |
Share: ASP displays long numbers separated by commas The following is the quoted content: 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000