- ASP.NET Web Pages - Tutorial
- ASP.NET Web Pages - Adding Razor Code
- ASP.NET Web Pages - Page Layout
- ASP.NET Web Pages - Folders
- ASP.NET Web Pages - Global Pages
- ASP.NET Web Pages - HTML Forms
- ASP.NET Web Pages - Objects
- ASP.NET Web Pages - Files
- ASP.NET Web Pages - Databases
- ASP.NET Web Pages - Helpers
- ASP.NET Web Pages - The WebGrid Helper
- ASP.NET Web Pages - The Chart Helper
- ASP.NET Web Pages - The WebMail Helper
- ASP.NET Web Pages - WebSecurity Object
- ASP.NET Web Pages - Publishing The Website
- ASP.NET Web Pages - Classes
- ASP.NET Razor - Markup
- ASP.NET Razor - C# And VB Code Syntax
- ASP.NET Razor - C# Variables
- ASP.NET Razor - C# Loops And Arrays
- ASP.NET Razor - C# Logic Conditions
- ASP.NET Razor - VB Variables
- ASP.NET Razor - VB Loops And Arrays
- ASP.NET Razor - VB Logic Conditions
- ASP Tutorial
- ASP Syntax
- ASP Variables
- ASP Procedures
- VBScript Conditional Statements
- VBScript Looping
- ASP Forms And User Input
- ASP Cookies
- ASP Session Object
- ASP Application Object
- ASP Including Files
- ASP The Global.asa File
- ASP AJAX
- ASP Sending E-mail With CDOSYS
- VBScript Functions
- VBScript Keywords
- ASP Response Object
- ASP Application Object
- ASP Session Object
- ASP Server Object
- ASP ASPError Object
- ASP FileSystemObject Object
- ASP TextStream Object
- ASP Drive Object
- ASP File Object
- ASP Folder Object
- ASP Dictionary Object
- ASP AdRotator Component
- ASP Browser Capabilities Component
- ASP Content Linking Component
- ASP Content Rotator Component (ASP 3.0)
- ASP Quick Reference
- ADO Introduction
- ADO Database Connection
- ADO Recordset
- ADO Display
- ADO Queries
- ADO Sort
- ADO Add Records
- ADO Update Records
- ADO Delete Records
- ADO Demonstration
- ADO Speed Up With GetString()
- ADO Command Object
- ADO Connection Object
- ADO Error Object
- ADO Field Object
- ADO Parameter Object
- ADO Property Object
- ADO Record Object
- ADO Recordset Object
- ADO Stream Object
- ADO Data Types
ASP Including Files
The #include Directive
You can insert the content of one ASP file into another ASP file before the server executes it, with the #include directive.
The #include directive is used to create functions, headers, footers, or elements that will be reused on multiple pages.
Practice Excercise Practice now
How To Use The #include Directive
Here is a file called "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>
Here is the "wisdom.inc" file:
the number of entities required to explain anything."
Here is the "time.inc" file:
Response.Write(Time)
%>
If you look at the source code in a browser, it will look something 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>
Practice Excercise Practice now
Syntax For Including Files
To include a file in an ASP page, place the #include directive inside comment tags:
or
<!--#include file ="somefilename"-->
Practice Excercise Practice now
The Virtual Keyword
Use the virtual keyword to indicate a path beginning with a virtual directory.
If a file named "header.inc" resides in a virtual directory named /html, the following line would insert the contents of "header.inc":
Practice Excercise Practice now
The File Keyword
Use the file keyword to indicate a relative path. A relative path begins with the directory that contains the including file.
If you have a file in the html directory, and the file "header.inc" resides in html\headers, the following line would insert "header.inc" in your file:
Note that the path to the included file (headers\header.inc) is relative to the including file. If the file containing this #include statement is not in the html directory, the statement will not work.
Practice Excercise Practice now
Tips And Notes
In the sections above we have used the file extension ".inc" for included files. Notice that if a user tries to browse an INC file directly, its content will be displayed. If your included file contains confidential information or information you do not want any users to see, it is better to use an ASP extension. The source code in an ASP file will not be visible after the interpretation. An included file can also include other files, and one ASP file can include the same file more than once.
Important: Included files are processed and inserted before the scripts are executed. The following script will NOT work because ASP executes the #include directive before it assigns a value to the variable:
fname="header.inc"
%>
<!--#include file="<%fname%>"-->
You cannot open or close a script delimiter in an INC file. The following script will NOT work:
For i = 1 To n
<!--#include file="count.inc"-->
Next
%>
But this script will work:
<!--#include file="count.inc" -->
<% Next %>
Practice Excercise Practice now
Products
Partner
Copyright © RVR Innovations LLP 2025 | All rights reserved - Mytat.co is the venture of RVR Innovations LLP