ASP Quick Reference
ASP Quick Reference from Runoob Tutorial. Print it out, put it in your pocket, and have it handy at any time.
Basic Syntax
ASP scripts are enclosed by <% and %>. Write output to the browser:
<% response.write("Hello World!") %>The default language in ASP is VBScript. To use another scripting language, insert a language declaration at the top of the ASP page:
<%@ language="javascript" %>
<%
....
%>
Forms and User Input
Request.QueryString is used to collect values from a form with method="get". Information sent from a form using the GET method is visible to all users (it appears in the browser's address bar), and there is a limit on the amount of information that can be sent.
Request.Form is used to collect values from a form with method="post". Information sent from a form using the POST method is invisible to users, and there is no limit on the amount of information that can be sent.
ASP Cookies
Cookies are often used to identify users. A cookie is a small file that a server leaves on a user's computer. Each time the same computer requests a page through a browser, it sends the cookie.
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 tag!
The "Request.Cookies" command is used to retrieve cookie values:
<%
fname=Request.Cookies("firstname")
response.write("Firstname=" & fname)
%>
Including Files
By using the #include directive, you can insert the content of another ASP file into an ASP file before the server executes it. The #include directive is used to create functions, headers, footers, or other elements that need to be reused on multiple pages.
Syntax:
or
Use the keyword virtual to indicate a path that starts with a virtual directory. If a file named "header.inc" is located in the virtual directory /html, the following line of code inserts the content of the "header.inc" file:
Use the keyword file to indicate a relative path. A relative path starts with the directory that contains the including file. If you have a file in the html directory and the "header.inc" file is located at the top of html, the following line of code inserts the content of the "header.inc" file into your file:
Use the keyword file with the syntax (..) to reference files in a higher-level directory.
Global.asa
The Global.asa file is an optional file that can contain declarations of objects, variables, and methods that are accessible to 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 have only one Global.asa file.
The Global.asa file can only contain the following:
- Application Events
- Session Events