From http://www.w3schools.com (Copyright Refsnes Data)

ASP Quick Reference

Previous Next

ASP Quick Reference from W3Schools. Print it, and fold it in your pocket.


Basic Syntax

ASP scripts are surrounded by <% and %>.  To write some output to a browser:

<html>
<body>
<% response.write("Hello World!") %>
</body>
</html>

The default language in ASP is VBScript. To use another scripting language, insert a language specification at the top of the ASP page:

<%@ language="javascript" %>
<html>
<body>

<%
....
%>

Forms and User Input

Request.QueryString is used to collect values in a form with method="get". Information sent from a form with the GET method is visible to everyone (it will be displayed in the browser's address bar) and has limits on the amount of information to send.

Request.Form is used to collect values in a form with method="post". Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.

ASP Cookies

A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests for a page with a browser, it will send the cookie too.

The Response.Cookies command is used to create cookies:

<%
Response.Cookies("firstname")="Alex"
Response.Cookies("firstname").Expires="May 10,2002"
%>

Note: The Response.Cookies command must appear BEFORE the <html> tag!

The "Request.Cookies" command is used to retrieve a cookie value:

<%
fname=Request.Cookies("firstname")
response.write("Firstname=" & fname)
%>

Including Files

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

Syntax:

<!--#include virtual="somefile.inc"-->
or
<!--#include file ="somefile.inc"-->

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":

<!-- #include virtual ="/html/header.inc" -->

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:

<!-- #include file ="headers\header.inc" -->

Use the file keyword with the syntax (..\) to include a file from a higher-level directory.

Global.asa

The Global.asa file is an optional file that can contain declarations of objects, variables, and methods that can be accessed by every page in an ASP application.

Note: The Global.asa file must be stored in the root directory of the ASP application, and each application can only have one Global.asa file.

The Global.asa file can contain only the following:

Application and Session Events

In Global.asa you can tell the application and session objects what to do when the application/session starts and what to do when the application/session ends. The code for this is placed in event handlers. Note: We do not use <% and %>, to insert scripts in the Global.asa file, we have to put the subroutines inside the HTML <script> tag:

<script language="vbscript" runat="server">
sub Application_OnStart
  ' some code
end sub
sub Application_OnEnd
  ' some code
end sub
sub Session_OnStart
  ' some code
end sub
sub Session_OnEnd
  ' some code
end sub
</script>

<object> Declarations

It is also possible to create objects with session or application scope in Global.asa by using the <object> tag. Note: The <object> tag should be outside the <script> tag!

Syntax:

<object runat="server" scope="scope" id="id"
{progid="progID"|classid="classID"}>
.......
</object>

TypeLibrary Declarations

A TypeLibrary is a container for the contents of a DLL file corresponding to a COM object. By including a call to the TypeLibrary in the Global.asa file, the constants of the COM object can be accessed, and errors can be better reported by the ASP code. If your Web application relies on COM objects that have declared data types in type libraries, you can declare the type libraries in Global.asa.

Syntax:

 <!--METADATA TYPE="TypeLib"
file="filename"
uuid="typelibraryuuid"
version="versionnumber"
lcid="localeid"
-->

The Session Object

The Session object is used to store information about, or change settings for a user session. Variables stored in the Session object hold information about one single user, and are available to all pages in one application.

Collections

Properties

Method

Application Object

A group of ASP files that work together to perform some purpose is called an application. The Application object in ASP is used to tie these files together. All users share one Application object. The Application object should hold information that will be used by many pages in the application (like database connection information).

Collections

Methods

The Response Object

The Response Object is used to send output to the user from the server.

Collection

Properties

Methods

Request Object

When a browser asks for a page from a server, it is called a request. The Request Object is used to get information from the user.

Collection

Property

Method

Server Object

The Server Object is used to access properties and methods on the server.

Property

Method

Source : http://www.w3schools.com/asp/asp_quickref.asp


Previous Next

From http://www.w3schools.com (Copyright Refsnes Data)