Web Hosting Guides

ASP Training - The Basics

This page will give you the basics of ASP, and this will be asp dedicated to web page output; so we will look at creating pages with ASP; outputting variables; using loops and processing HTML form information for display.


Creating an ASP Page

ASP is, at its most simple, nothing more than a special kind of HTML markup that is interpreted before sending back the viewing browser. To change a basic HTML page into an ASP page all you need to do is change the file extension to .asp! You can see this by looking at this demonstration page.


The page is just HTML, and the code is as follows.


<html>
<head>
<title>asp demonstration - an asp page with just html markup</title>
</head>
<body>
<h1>Only HTML - no asp</h1>
This page just has HTML, no asp at all, all that is different is that the file extension of the page is .asp instead of .htm (or .html).
</body>
</html>


So you can see that the only thing different from a standard HTML page is that if you look at the URL (look at Netsite or Location in Netscape; or Address in Internet Explorer) you will see that it ends in .asp rather than .html


So, now you have an ASP page with no ASP. Not very useful, but it shows you how easy it is to go about generating your first ASP page.


Lets make things more interesting by slowly adding some of the ASP that was introduced in.


Starting with ASP.


The first bit of ASP was <%@ LANGUAGE="VBSCRIPT" %>. What do all the bits mean? <% and %> are two tags that you will get thoroughly sick of. These tags tell the page that anything between them is ASP and so needs to be interpreted (run) rather than just displayed. These two tages are what allow you to have both HTML and ASP in the same page, when the web server sends the page back to the browsers it will just send any HTML it finds, and anything between the two tags it knows to handle differently and to run as code.


The other thing to note is that looking through that first script for <%and %> is that there is not just one occurance of these two tags, but they can appear as often as required; so you can have some HTML; then some ASP; then some HTML; and some ASP; ad nauseam.


Right, now you know what <% and %> are for; what is that @ LANGUAGE="VBSCRIPT" for. Strictly speaking it is not actually necessary if you are using ASP with VBscritp (as we are doing). What that line does (as long as it is the very first line in the script; is to tell the web server to interpret any asp using VBScript. Now, why would you need to tell the web server to use VBScript? Well, although ASP, by default, uses VBScipt as standard; it also comes with JavaScript, so you could write your ASP pages using JavaScript! Not only that, but there are some other languages that you can get to use with ASP, such as perlScript. If you want to use these other languages you will need to tell the web server that that is what you are doing (and if you are using somthing other than VBScript or JavaScript you will need to install the appropriate software.


So you now know how to recognise ASP tags, and also what @ LANGUAGE="VBSCRIPT" is all about, so know lets move away from the boring stuff and onto the real thing. The next ASP line in the first script is <% response.write("using ASP to write to the page") %>. What does this do? Well, you should be able to spot that from the words and also by looking at the output of the script! Oh, you want some explanation? All that response.write does is allow you to write to the HTML page from inside an ASP script. In this case we are writing out the text string "using ASP to write to the page". Not much point in that as we could just have easily written "using ASP to write to the page" in HTML and saved ourselves the hassel of messing about with ASP. True : but you're forgetting that this is a training page! Besides, you can use response.write for more than just outputting text. You can also use it to output the values of variables that you use in ASP scripts. More of which on next page!

Advertisements


Popular Countries




Choose a letter