HOME

ASP Tutorial
ASP HOME
ASP Introduction
ASP Install
ASP Syntax
ASP Variables
ASP Procedures
ASP Forms
ASP Cookies
ASP Session
ASP Application
ASP #include
ASP Global.asa

ASP Objects
ASP Response
ASP Request
ASP Application
ASP Session
ASP Server
ASP Error

ASP FileSystem
ASP TextStream
ASP Drive
ASP File
ASP Folder
ASP Dictionary

ASP Components
ASP AdRotator
ASP BrowserCap
ASP Content Linking
ASP Content Rotator

ASP Quick Ref

Examples/Quiz
ASP Examples
ASP Quiz Test

ADO
ADO Introduction

Resources
ASP Resources
Award Winning Web Host Full Services Including Ecommerce
Please visit our sponsors !

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 the delimiters <% 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, like JavaScript, insert a language specification at the top of the ASP page:

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

<%
....
%>

ASP Cookies

A cookie can be used to identify a user. It is a small file that the server embeds on the user's computer. Each time the same computer asks for a page through a browser, it will send the cookie too.

The "Response.Cookies" command is used to create a cookie:

<%
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 get a cookie value.

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

Including Files

The #include directive is used to insert the content of another file into an ASP file before the server executes it. This 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. For example, if a file named header.inc resides in a virtual directory named /html, the following line would insert the contents of header.inc into the file containing the line:

<!-- #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. For example, if you have a file in the directory html, and the file header.inc is 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

An optional file where you can specify event scripts and declare session and application objects.

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.

In this file 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 are placed into 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> element:

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

The Session Object

Stores information (like name, id, and preferences) about, or change settings for a user session. Variables stored in the Session object holds information about one single user, and are available to all pages in one application. The server creates a new Session object for each new user, and destroys the Session object when the session expires.

Syntax

Session.collection
Session.property
Session.method

Collections

  • Contents - Holds every item added to the session with script commands
  • StaticObjects - Holds every object added to the session with the <object> tag, and a given session
  • Contents.Remove(item/index) - Deletes an item from the Contents collection
  • Contents.RemoveAll() - Deletes every item from the Contents collection

Properties

  • CodePage - Sets the code page that will be used to display dynamic content
  • LCID - Sets the locale identifier that will be used to display dynamic content
  • SessionID - Returns the session id
  • Timeout - Sets the timeout for the session

Method

  • Abandon - Kills every object in a session object

Application Object

Store variables and access variables from any page. 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).

Syntax

Application.collection
Application.method

Collections

  • Contents - Holds every item added to the application with script commands
  • StaticObjects - Holds every object added to the application with the <object> tag
  • Contents.Remove - Deletes an item from a collection
  • Contents.RemoveAll - Deletes every item from a collection

Methods

  • Lock - Prevents a user from changing the application object properties
  • Unlock - Allows a user to change the application object properties

The Response Object

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

Syntax

Response.collection
Response.property
Response.method

Collection

  • Cookies(name) - Sets a cookie value. If the cookie does not exist, it will be created, and take the value that is specified

Properties

  • Buffer - Whether to buffer the output or not. When the output is buffered, the server will hold back the response until all of the server scripts have been processed, or until the script calls the Flush or End method. If this property is set, it should be before the <html> tag in the .asp file
  • CacheControl - Sets whether proxy servers can cache the output or not. When set to Public, the output can be cached by a proxy server
  • Charset(charset_name) - Sets the name of the character set (like "ISO8859-1") to the content type header
  • ContentType - Sets the HTTP content type (like "text/html", "image/gif", "image/jpeg", "text/plain"). Default is "text/html"
  • Expires - Sets how long a page will be cached on a browser before it expires
  • ExpiresAbsolute - Sets a date and time when a page cached on a browser will expire
  • IsClientConnected - Checks if the client is still connected to the server
  • Pics(pics_label) - Adds a value to the pics label response header
  • Status - Specifies the value of the status line

Methods

  • AddHeader(name, value) - Adds an HTML header with a specified value
  • AppendToLog string - Adds a string to the end of the server log entry
  • BinaryWrite(data_to_write) - Writes the given information without any character-set conversion
  • Clear - Clears the buffered output. Use this method to handle errors. If Response.Buffer is not set to true, this method will cause a run-time error
  • End - Stops processing the script, and return the current result
  • Flush - Sends buffered output immediately. If Response.Buffer is not set to true, this method will cause a run-time error
  • Redirect(url) - Redirects the user to another url
  • Write(data_to_write) - Writes a text to the user

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.

Syntax

Request.collection
Request.property
Request.method

Collection

  • ClientCertificate - Holds field values stored in the client certificate
  • Cookies(name) - Holds cookie values
  • Form(element_name) - Holds form (input) values. The form must use the post method
  • QueryString(variable_name) - Holds variable values in the query string
  • ServerVariables(server_variable) - Holds server variable values

Property

  • TotalBytes - Holds the total number of bytes the client is sending in the body of the request

Method

  • BinaryRead - Fetches the data that is sent to the server from the client as part of a post request

Server Object

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

Syntax

Server.property
Server.method

Property

  • ScriptTimeout - Sets how long a script can run before it is terminated

Method

  • CreateObject(type_of_object) - Creates an instance of an object
  • Execute(path) - Executes a .asp file from inside another .asp file. After executing the called .asp file, the procedural control is returned to the the original .asp file
  • GetLastError() - Returns an ASPError object that will describe the error that occurred
  • HTMLEncode(string) - Applies HTML encoding to a string
  • MapPath(path) - Maps a relative or virtual path to a physical path
  • Transfer(path) - Sends all of the state information to another .asp file for processing. After the transfer, procedural control is not returned to the original .asp page
  • URLEncode(string) - Applies URL encoding rules to a string

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


Previous Next

Jump to: Top of Page or HOME or Printer Friendly Printer friendly page


Search W3Schools:


What Others Say About Us

Does the world know about us? Check out these places:

Dogpile Alta Vista MSN Google Excite Lycos Yahoo Ask Jeeves


We Help You For Free. You Can Help Us!


W3Schools is for training only. We do not warrant its correctness or its fitness for use. The risk of using it remains entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.

Copyright 1999-2002 by Refsnes Data. All Rights Reserved


Validate How we converted to XHTML Validate

IISProtect
Password Protect
Your Web Pages



Your own Web Site?

Read W3Schools
Hosting Tutorial



$15 Domain Name
Registration
Save $20 / year!



Advertise
at W3Schools

Only 0.5 CPM



SELECTED LINKS

University Online
Master Degree
Bachelor Degree


Web Software

The Future of
Web Development


Jobs and Careers

Web Security
Web Statistics
Web Standards


PARTNERS

W3Schools
TopXML
VisualBuilder
XMLPitstop
DevelopersDex
DevGuru
Programmers Heaven
The Code Project
Tek Tips Forum
ZVON.ORG
TopXML Search