Advertise here.

Tuesday 28 August 2012

ASP Lesson #1 - Introduction to ASP


This tutorial will teach you how to use ASP(Active Server Pages). It only includes the most important things that you need to know about ASP and leaves out the things that are not used very often. This means that you will learn ASP quicker and not have to go through boring things that you might never use.

Requirements

If you are using Windows 95 or NT 4.0 you need to download and install the Windows NT 4.0 Option Pack.

If you are using Windows 98 then you need to install Personal Webserver from your Windows 98 CD.

If you are using Windows 2000 or XP then you need to install IIS(Internet Information Services) from Control Panel->Add or Remove Programs->Add/Remove Windows Components.

If you don't have any of those then you can get yourself an ASP webhosting account but it is a lot more difficult to learn doing it this way.

You need Microsoft Access if you want to learn about using a database with ASP and you need to know how to use Access.

Other things that you are not required to know but that will help you are:
  • HTML Forms
  • Visual Basic
  • SQL

First ASP Page

We will be creating our ASP pages using Notepad. Open Notepad and type the following code for a basic html page:

<html>

<head>
<title>My First ASP Page</title>
</head>

<body>
</body>

</html>

Now type the following before all the HTML code:

<% @Language = VBScript %>

This tells the webserver that we will be using VBScript as the scripting language in our ASP page. Next you must add the following line straight after the one you have just typed:

<% Option Explicit %>

This tells the webserver that all variables must be declared before they can be used. We will learn about variables later. It is important that you put those 2 lines on all your ASP pages.

All ASP code must be put between an opening <% and a closing %> tag. Your main ASP code should go between the <body> tags.

We will now write the words "Hello World" on our ASP page. The Response.Write command is used to write things. Type the following between the ASP tags:

Response.Write "Hello World"

You can write comments that are ignored by the webserver by typing them after a '. You can write a comment which tells you what the Response.Write to see how it is done. Here is what you should type:

' Writes the words Hello World

Here is what you should have so far:

<% @Language = VBScript %>
<% Option Explicit %>
<html>

<head>
<title>My First ASP Page</title>
</head>

<body>
<%
' Writes the words Hello World
Response.Write "Hello World"
%>
</body>

</html>

Another way to write things is to use just an = in front of what you want to write but you can only do it this way if it is put inside its own set of ASP tags. Here is an example:

<% ="Hello World" %>

You must now save your ASP page. Save it as first.asp in C:\Inetpub\wwwroot. Make sure you choose All Files for the Save as Type. If you don't have a C:\Inetpub\wwwroot folder then you have not installed PWS or IIS. Now open your web browser and go to the http://localhost/first.asp. If you have done everything right then you will see a page that says 
Hello World. Congratulations you have just made your first ASP page.

If you do a View Source on the page that is displayed in your browser you will see that the ASP tags have disappeared. This is because everything between the ASP tags are processed before it is sent to the browser. It is important to understand that the file that the browser receives it not the same ASP file that you created. Don't try editing your ASP file by doing a View Source because it won't work.

0 comments:

Post a Comment