Using Includes in ASP

A simple form of server side includes is including a file before a page is sent to the browser.  The code is as follows:

<!-- #include virtual="foo.html" -->

Virtual Includes can be useful in several contexts, such as including the same code in several pages or to include code but keep your attention in coding on other portions of the code rather than the code you are including.

A trivial example of using a virtual include: 

includejs.asp file:

<%@ LANGUAGE="JScript" %>
<% connCW = Server.CreateObject("ADODB.Connection") 
connCW.Open("Driver={Microsoft Access Driver (*.mdb)}; DBQ=" + Server.MapPath("registration.mdb"));
rsItem = connCW.Execute("SELECT * from students") %>
<!-- #include virtual="heading.htmlf" -->
<% while (!rsItem.EOF) { %>
<tr>
<td><% =rsItem("sid") %></td>
<td><% =rsItem("first") %></td>
<td><% =rsItem("last") %></td>
<td><% =rsItem("state") %></td>
</tr> 
<% rsItem.MoveNext() }
connCW.Close() %>
</table>
</body>
</html>

heading.htmlf (use of this extension is a convention to indicate that it is a fragment)

<html>
<head>
</head>
<body>
<table>
<tr>
<td>ID</td>
<td>First Name</td>
<td>Last Name</td>
<td>State</td>
</tr>

Revised: September 29, 2002.  Comments to William Pegram, wpegram@nvcc.edu