There are four kinds of tags demarcating ASP server-side script on an ASP page. All other code on the page is on the HTML page itself, ie is client-side, and is visible client-side.

  1. <%@ ... %>. ASP Processing Directives are used to enclose information about the script authoring environment. In Classic ASP, this is commonly used to set the server-side language. In ASP.NET, this is commonly used to set up the CodeFile for code-behind.
  2. <% ... %>. Used to enclose standard ASP server-side script. Script comments are not passed on to the browser but HTML comments are.
  3. <%= ... %>. ASP Output Directives are used to enclose output directive information (equivalent to Response.Write). Script comments are not allowed within ASP output tags.
  4. <script runat="server" language="scriptingLanguage"> ... </script> or <script runat="server" language="scriptingLanguage" src="SourceFile"></script>. These kind of tags can only contain sub-routines, not free standing code. These are generally run before code in <% ... %>. Good for specifying script language on a per-block basis.


Note that the top of the example is typical for many ASP pages. 

<% Option Explicit 'Forces explicit declaration of server-side variables. 
Response.Buffer = True 'Makes server get everything done before sending to the client.
Response.Expires = -1 'Makes the server not cache the page.
<!-- An SSI directive can be used to insert another file. / -->
<!-- This include inserts the VBS constants for ADO. / -->
<!-- #include file="..\includes\" -->
<!-- This include inserts relative to the virtual root. / -->
<!-- #include virtual="\site\SSUtilities.vbs" -->

<title>Sample ASP</title>
<script langauge="JavaScript">
  //This is client-side script. </script>
<!-- This HTML comment is client-side. / -->
<% 'Here's some server-side script.
myVariable = "I'm OK and "
mOtherVariable = "you're "
Response.Write "<p>Hello"
%> world!</p>

<p><%= myVariable 'THIS COMMENT IS ILLEGAL %>
<%= myOtherVariable & "OK." %></p>

<script runat="server" language="JavaScript">
  Response.Write "<p>bye-bye</p>"
// / -->


The ASP processing directive which denotes the server side scripting language used (EG: <%@ language="VBScript" %>) is usually the first real line of an ASP page. It is common practice to have it and other common code put at the top of a page via an Server Side Include (SSI) directive (EG: <!-- #include file="ssVBS.asp" --> or <!-- #include virtual="/ssVBS.asp" -->: The former is virtual while the latter is relative.). Note that if you want to have the server side code properly color coded by the Visual InterDev IDE, and your server side scripting language is not VBScript, then you will want to not include the ASP processing directive included in the SSI directive, i.e. the top of each page would be like this: <%@ language="JavaScript" %><!-- #include file="\ssJS.asp" -->.

The file indicated by an SSI cannot be a variable since includes are processed and inserted before the server process the ASP script. EGs:

<% 'This will not work %>
<!-- #include virtual=\includes\file<%= x %>.asp -->
<% 'This will work %>
<% If x = 1 Then %>
<!-- #include virtual=\includes\file1.asp -->
<% Else %>
<!-- #include virtual=\includes\file2.asp -->
<% End If %>
<% 'This will also work
If x = 1 Then
End If

GeorgeHernandez.comSome rights reserved