1. ASP intro
  2. ASP basics
  3. ASP variables
  4. ASP operators

ASP basics

ASP code can be declared in various places, be written in Javascript or VBScript, and can be used to print text as well as contain HTML tags.

This tutorial focuses on:

Declaring an ASP script within a webpage

An ASP script begins with <% and ends with %>. It can be placed anywhere within a webpage. You can have as many scripts within a webpage as you want.

<% script contents go here %>
<html> <head> <title>ASP script</title> </head> <body> <% Response.Write "ASP is cool!"; %> </body> </html>
ASP is cool

Including VBScript code

Since VBScript is the default language of ASP, you do not have to explicitly mention to ASP that you want to include VBScript code, you just do it as in the above example as well as in the below example.

<html> <head> <title>ASP script written in VBScript</title> </head> <body> <% Response.Write "VBScript by default! %> </body> </html>
VBScript by default!

Including Javascript code

Including Javascript code in ASP is different than including VBScript code. To include Javascript code in ASP you have to have a language specification at the top of a page that looks like this:

<%@ language="javascript"%>
<%@ language="javascript"%> <html> <head> <title>ASP script written in Javascript</title> </head> <body> <% Response.Write("Javascript and ASP!") %> </body> </html>
Javascript and ASP!

This language specification will tell ASP that a script is going to contain Javascript.

NOTE: The language specification should be the first line of code on the page or you will get an error.

NOTE: JavaScript is case sensitive unlike VBScript. You will have to be careful with uppercase and lowercase letters when including Javascript code in ASP.

Can ASP include other languages besides Javascript and VBScript?

Yes, but if you want to use any other languages besides Javascript and VBScript, you will have to install the necessary script engines for them.

NOTE: Javascript and VBScript are both client-side languages but when included in ASP, they are executed on the server-side.

NOTE: ASP does not include the general Javascript language, but JScript which is Microsoft's implementation of Javascript. Read more about JScript at Microsoft's JScript page.

Printing text on a webpage

Printing text on a webpage with ASP is simple. To do so use the Response.Write() statement.

<% Response.Write("ASP stands for Active Server Pages") %>
ASP stands for Active Server Pages

Alternatively, you could just use an equal sign instead of the Response.Write() statement like this:

<%="ASP stands for Active Server Pages"%>
ASP stands for Active Server Pages

Including HTML tags in a script

HTML tags can be included in a script by including them together with regular text. Any tags included in a script this way will be interpreted by the web browser as regular HTML.

<html> <head> <title>HTML tags in scripts</title> </head> <body> <% Response.Write("<b><i>This text will be bold and italic</i></b>") Response.Write("<br /><a href=''> main page</a>") %> </body> </html>
This text will be bold and italic main page

Including comments in a script

Comments in ASP are declared so that code would be easier to understand and to navigate. Comments are not seen on a webpage, but only within the source code. Comments can be placed anywhere within ASP source code. In ASP you can have only single line comments, no multi-line comments like in some other languages. Single line comments in ASP are declared with the apostrophe ( ' ) symbol.

<html> <head> <title>Comments in ASP</title> </head> <body> <?% 'this is a single line comment 'this is another single line comment Response.Write("This script contains some comments") %> </body> </html>
This script contains some comments

NOTE: Single line comments can span only a single line.

Special characters

ASP uses some special characters and knowing them is fundamental to writing scripts with ASP:

Special characters example:
<% a = 1 : b = 2 : c = 3 : d = 4 'as opposed to...... a = 1 b = 2 c = 3 d = 4 Response.Write("This text string " & "is combined.") 'this line of text is a comment 'so is this one Response.Write("This is a really " & _ "really really really really really really " & _ "long sentence.") %>
This text string is combined. This is a really really really really really really really long sentence.
© Copyright 2013-2014
Terms of use | Privacy policy | Copyright information