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
- Including VBScript code
- Including Javascript code
- Printing text on a webpage
- Including HTML tags in a script
- Including comments in a script
- Special characters
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.
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.
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:
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.
Alternatively, you could just use an equal sign instead of the Response.Write() statement like this:
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.
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.
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:
- & - the "concatenation" operator, used to combines text strings.
- ' - used to declare a comment
- _ - the underscore character, used to span multiple lines of ASP code.
- : - line extender. Use the colon character (:) to put multiple lines of code on one line. Although this is not recommended because it makes code harder to read.
