http://www.developer.com/net/vb/article.php/865861/An-Active-Server-Pages-Tutorial-Part-1.htm
Active Server Pages (ASP) is one of the
most exciting and interesting Internet technologies ever created by Microsoft.
With ASP, developers can build dynamic websites very easily. A script
running on the server receives a request from the client and generates a
customized HTML page, which will be returned to the client. ASP
is available with Microsoft IIS (Internet Information Server). It is available only with
the Windows NT operating system. If you are using Windows 98 or 2000, you can
use Microsoft Personal Web Server to test your ASP scripts. Since pure HTML is generated, it obviously works on browsers such as Internet Explorer
and Netscape. The script in an ASP page can be written by using Visual Basic Script, JavaScript,
or JScript (or ECMAScript). JScript is the Microsoft Version of JavaScript. You should use
Notepad or any other text editor to write your code. The most ideal tool for coding ASP is
Microsoft Visual Interdev. After typing your code, you should save the
file with the extension .asp if you use Notepad. If
you are using Microsoft Visual Interdev, your .asp file is
automatically saved as a .asp file. (See the end of this Session for
more information about this tool.) An ASP page also contains HTML tags. So how will the
server distinguishes between ASP script code and HTML tags? It is
through the special <% ---- %> tags, called delimiters. The script
within <%----%> executes on the Web server. The other type of
delimiter is <% = ---%>, which is mainly used for output expressions. For
example, consider the following script: Here, total is a VBScript variable. The value of the
variable total will be displayed as output. Type in the following script in a text editor or Visual Interdev. Save the file as Example 1.1 in the <a
href="file:///C:/Inetpub/wwwroot">C:Inetpubwwwroot</a>
directory. You should save all your ASP files in this directory so that
the server can be able to locate the files and execute them. Otherwise,
you can create a virtual directory and configure the server (creating alias)
appropriately. Then you can access the .asp files using that alias name. Click
on the Advanced options in the Microsoft Personal Web Server. Now, it's time to fire up your Web browser to view the output. Open
your browser and type
Click File - New File and select ASP page to type your script. This will
add a new ASP file page for you. You will notice the unique coloring to
the code which will automatically appear as you write your Script. Let's begin our discussion by examining a classic Hello World ASP program.
Now Consider this:
This is a typical VBScript statement, except that the delimiters tell the server to
execute the code. (The script tag is also used as a delimiter.) >You can easily embed server-side script in the
<Script> tag. When you use the <SCRIPT> tag, you must
include the RUNAT attribute, which you set to Server. The Object Response is an intrinsic Active
Server component that allows you to send output to the client. Another object request
allows you to request info from the server. Response Object ---> Server to
Client Request Object
---> Client to Server VBS Supports only one data type, the variant.
The variant data type can contain different types of data,
depending on how it is used. The different data types
represented by the variant are called subtypes, such as
Boolean, Byte, Currency, Date, Double, etc. Consider the following script: Analysis: Line 1: It gives a value of 100. The + operator indicates arithmetic.
VBS temporarily converts the string "25" to a number and performs the
arithmetic operation. Line 2: Indicates line break. Line 3: Visual Basic script converts the integer 75 to a string and appends to
the string "25". Now Consider this script: This is an error. It will indicate type mismatch. A variable is simply a location in memory that
has been given a name and whose contents can be changed. Data
is placed in the variable and subsequently accessed through the
Variable name. Consider the following script: The above statement declares the variable
The
Implicit and Explicit Variables:
Dim greetings. Here, there is no type information, since all variables
are variants in VBScript. You can declare multiple names like Dim, greetings, age,
etc. Including Option Explicit Statement: If you include this statement and later try to implicitly
declare a variable, VBScript will generate an
"undefined variable" error message. See the code below. Variable Scope
The two levels of scope in VBScript are script level and procedure level. 1. Script Level: A variable has script-level scope when it is declared outside
a procedure. It can be used anywhere in the script after declaration. It is
similar to a global variable. It exists until the script finishes executing. 2. Procedure Level: Variables declared within a procedure have procedure-level
scope and are available only within the procedure. They are also called as local variables.
They exist until the procedure finishes executing. Private and Public Variables Private: Creates variables that are available only in the script that declares
them. Public: Creates variables that are available
to all scripts. You can use this only at the script level. In Part 2, we will show you Boolean functions in ASP, session and application methods,
use of text files, and database access.
An Active Server Pages Tutorial, Part 1
August 14, 2001
SESSION 1
Introduction to Active Server Pages
Overall Working of an ASP Page
How to Write an ASP Page
<% =total%>
Example 1.1
<body>
<% for I = 1 to 7 %>
<font size = <%=I%>>ASP IS GREAT!!!</font><br>
<%next%>
</body>
<a href="http://localhost/Example1.1.asp">http://localhost/Example1.1.asp</a>
in the address bar. If every thing goes well, you should view the text
ASP IS GREAT seven times with different font sizes.
SESSION 2
Getting Started Using ASP
<html>
<head>
<title>Hello World</title>
<% = "HelloWorld"%>
</head>
<body>
</body>
</html>
Analysis:
<% fontsize = 5 %>
How to Use the <Script> Delimiter
<html>
<head><title>ASP</title>
<script language = vbs RUNAT = server>
response.write("Hello World")
</script>
</head>
</html>
SESSION 3
Data Types
1. <% = "25" +75 %>
2. <% = "<br>" %>
3. <% = "25" &75 %>
<%
"vbs" +75 %>
SESSION 4
Variables in ASP
<% strgreeting = "Hello World" %>
<% =strgreeting %>
strgreeting and assigns a string value to it.= operator assigns values to variables. The
output of the above program will be Hello World.
<% option Explicit
Dim greetings
Greetings = "Good Morning" ---------------> Allowed
Name = "David" ------------------------------> Not Allowed
%>
How to Name Variables
# , ~ , /, etc.Session 5
Built-in Functions
Though you cannot use the message
box and input box functions found in VBScript in server-side scripting,
there are some useful built-in functions which you can use in scripts.
They are outlined in the chart given below.
Function
Usage
Description
Date
<% =date %>
Returns the current date of the server
Time
<% =time %>
Returns the current time of the server
Now
<% =now %>
Returns both the date and time
Day
<% =day(now) %>
Returns the day of the current month
Year
<% =year(now) %>
Returns the current year
Weekday
<% =weekday(now) %>
Returns the day of the week by name
Weekdayname
<% = weekdayname(now) %>
Returns the weekday by name
About the Author
Anand Narayanaswamy is a graduate, in commerce, from the University of Kerala. He is currently working as an instructor teaching Java, Visual Basic, and other Web technologies, such ASP and XML. Currently, Anand lives in Thiruvananthapuram, Kerala State, India. He can be reached via his Website http://www.learnxpress.com.