ASP stands for Active Server Pages. They basically contain server-side scripts to result in dynamic websites. Server-side scripts are nothing but scripts which do some useful work at the server itself, and the processed HTML result is sent to the client side for the browser to display. Dynamic websites mean sites that may contain database connectivity used for surveys, polls, login & authentication, and so on. Remember that database connectivity is not the only factor which makes a website dynamic in nature. Server-side scripts start with <;% and end with %>;.
To run ASP sites you need an ASP-enabled web server like Microsoft Internet Information Server (IIS) or Microsoft Personal Web Server (PWS). All ASP pages are saved with a '.asp' extension to differentiate them with plain HTML files. Now let us make a basic ASP script for display the famous words 'Hello, World!':
<;HTML>;<br \\>
<;HEAD>;<br \\>
<;TITLE>;Hello, World!<;/TITLE>;<br \\>
<;/HEAD>;<br \\>
<;BODY>;<br \\>
<;%<br \\>
Response.Write Hello, World!<br \\>
%<;<br \\>
<;/BODY><br \\>
<;/HTML><br \\>
Notice that we have used VBScript here to display the string. You can also do this in another shorter, but a little unclear way, as shown below:
<;HTML><br \\>
<;HEAD><br \\>
<;TITLE>Hello, World!</TITLE><br \\>
<;/HEAD><br \\>
<;BODY><br \\>
<;%= Hello, World! %>;<br \\>
<;/BODY><br \\>
<;/HTML>;<br \\>
The above code shows the same result, the difference being that the second version replaces the 'Response.Write' by '='. Now let us see how we display the date and time using the inbuilt function 'Now' of VBScript. Take a look at the code below:
<;HTML>;<br \\>
<;HEAD>;<br \\>
<;TITLE>;Date and Time display example<;/TITLE>;<br \\>
<;/HEAD>;<br \\>
<;BODY>;<br \\>
<;%<br \\>
Response.Write Now<br \\>
%<;<br \\>
<;/BODY><br \\>
<;/HTML>;<br \\>
The above code will show you an output like
5/10/2005 11:15:71 PM
Next, we take a look at variables in ASP using VBScript. Suppose you want to declare a variable by the name of 'myvar'. This is how you'll do it in ASP:
<;%<br \\>
Dim myvar<br \\>
%<;<br \\>
This is very similar to declaring a variable in Visual Basic. 'Dim' stands for 'Dimension' and is used for declaring a variable. The only difference here being that unlike Visual Basic, we haven't declared a variable type. VBScript automatically treats all variables as variants. Infact, it is not even necessary to even declare variables before using them in VBScript. But all experienced programmers will tell you that this is not a good path to follow. Instead, it is better to enforce variable declaration using the directive 'Option Explicit'. This is shown in the example below:
<;%<br \\>
Option Explicit<br \\>
Dim myvar<br \\>
%<;<br \\>
This is a very brief introduction to the topic just to get you started. Look at sample code available at various websites, some of which I have included below. I'd personally recommend aspfree.com, which in my personal view is quite good. The other two sites are also top notch. And last of all, don't be afraid to ask intelligent questions on relevant forums. Good luck with ASP!
References:-
http://www.aspfree.com
http://www.asp101.com
http://www.hanend.com
Written by Rae, C/O of Knowledge Bank Tutorial Writing.
Edited by jehnx.
This article was originally published by CyberArmy.net in the CyberArmy Library.
|