This tutorial focuses on:
- Declaring an ASP script within a webpage
- Including VBScript 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.
NOTE: The language specification should be the first line of code on the page or you will get an error.
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.
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.