ASP (which stands for Active Server Pages according to ABBREVIATIONFINDER) is the technology for creating dynamic server-side pages developed by Microsoft. The type of servers that use this language are those that work with the Windows NT family of operating systems. We can also view ASP pages on Windows 95/98.
The ASP language was developed by Microsoft to work alongside its Internet Information Server. Its operation is very simple. When a client requests an ASP page from the server, it is interpreted by the server instead of sending it directly. As a result, the browser receives a page in pure HTML code, with the ASP commands already processed. This language is very powerful, especially if we are going to use Microsoft tools together, such as SQL Server. Additionally, additional components can be installed on the server to do things such as upload files or send e-mails.
Writing in ASP
There is a version of Visual Basic Script on the client side and another on the server side. In both cases, as its name indicates, the base language is Visual Basic, so its learning can be perfectly coordinated, since the sentences and syntax are practically the same.
Basic language syntax
- To write comments in code, you need to prepend a single quote to all text.
- They are not case-sensitive, neither for variable names nor for language functions.
- There is only one data type: Variant.
- The & operator is used to concatenate text strings.
- ASP snippets are placed between the <% and%> tags.
ASP is mainly used using the Visual Basic Script language, which is nothing more than a light version of Visual Basic. However, it is possible to program ASP pages in Java Script. All you have to do is specify on the page itself what type of language is being used.
Since the ASP language is very frequently embedded within the HTML code, it is important to be able to mark to the server which parts are written in one language and which in another. That is why all parts of the file that are written in ASP will always be delimited by the symbols: <% and%>.
In this way, when we make our scripts, the first thing we must define is the type of language used, which is done as follows:
<% @ LANGUAGE = “VBSCRIPT” %> For the case in which we program in Visual Basic Script <% @ LANGUAGE = “JSCRIPT” %> If we use the Java Script on the server to program in ASP
The scripts that will be presented in this article are based on VBS, which presents a whole series of features that make it undoubtedly more accessible and suitable for ASP.
Take a look at this example of a program to calculate the 20% tax to add to a series of items. To capture the concept of a function, a “imposed” function is defined that will be used successively. The program turns out like this:
<% @ LANGUAGE = “VBScript” %> <HTML> <HEAD> <TITLE> Funcion tax </ TITLE> </ HEAD> <BODY> <% Function tax (precio_articulo) precio_final = precio_articulo + precio_articulo * 20 / 100 Response. Write final_price End Function %> A book of 3500 ptas. will stay at a price of <% tax (3500) %> <br> A shirt of 6000 pesetas. will have a final price of <% tax (6000) %> <br> A music CD of 2000 pesetas. it would cost <% tax (2000 ) %> ptas. </BODY> </HTML>
As can be seen, the script contains two fundamental parts: The first one in which we define the function that we call tax that depends only on one variable (price_article). Tax allows you to add 20% to the price of the item and print the result on the screen (Response.Write). In the second part we use the function to perform the necessary calculations and display them on the screen accompanied by text.
Although it is necessary to declare variables, it is possible to create them explicitly with the Dim command. If we don’t use it, the variable will be created the same. In any case, and although it is not mandatory, it is convenient to get used to using Dim to declare variables. With this it is possible to avoid errors, since if we declare a variable twice, we will notice it through a warning from the ASP interpreter.
<% Dim a a = 23 b = ¨Text containing the variable¨ %>
If we want to declare a vector, we will first have to specify how many elements it has in the Dim statement and then load the elements separately or use the Array () function placing the elements as an argument:
<% Dim MyVector (3) MyVector (0) = ¨América¨ MyVector (1) = ¨Africa¨ MyVector (2) = ¨Europe¨ Other Vector = Array (¨Marcelo ¨, ¨Gisela ¨, ¨Armando ¨, ¨Sarita ¨) %>
Server Side Include
ASP gives us the possibility of including ASP files, or of any other type, within our page. This can be very useful in many cases, for example: if we have a file with commonly used functions that we are going to use many times on different pages, to always use the same header, footer and menu on all pages, to include a text file that is generated automatically, and everything that comes to mind. To include a file, the ASP <% and%> tags are not used, instead HTML comment tags are used as seen below:
<\ – # include file = ”functions.asp” ->
ASP is a language designed for creating applications on the Internet. This means that there are a whole series of fairly common tasks to which you must give an easy and efficient treatment (sending e-mails, accessing files, managing client or server variables).
The VB language itself does not provide an easy and direct solution to these tasks, but rather invokes so-called objects that are nothing more than modules incorporated into the language that allow the development of specific tasks. These objects carry out in a simple way a whole series of actions of a relevant complexity. From a call to the object, it will perform the required task.
Some of these objects are incorporated into the ASP itself, others must be incorporated as if they were accessory components. Of course, we could not correctly execute a script in which we had to call an object that was not integrated into the server. This type of “plug-in” is generally bought by the server from companies that develop them.
Like any object in the real world, objects in the computer world have their properties that define them, perform a certain number of functions or methods and are capable of responding in a definable way to certain events.
The future of ASP
This language still has a lot to offer us. Its flexibility allows you to add installable components to the server to perform many tasks that would otherwise be very difficult such as; upload files to the server, send e-mail messages and more. But Microsoft, the company that developed this technology, is tending to replace ASP with the new generation of .NET languages. How could it be otherwise, the future of ASP is called ASP.NET. Although the migration from one language to another will be slow and will take several years, mainly because in many cases it is not worth the investment, it is convenient to start researching and studying this new version and technology. Without a doubt, the starting point is www.asp.net, the official website.