This
tutorial will walk you through step-by-step of some of the basics to create
your own ASP website and applications. I am going to assume you already know a
little about HTML. If you don't, I suggest you check out my
web design section to bring you up
to speed on making html websites before you tackle ASP.
First
off, before you even to try to this exercise, Make sure you have read the
article What is ASP? and understand. And if
you understand it, then you should know that you have to have a server to run
ASP scripts. So, if anything I have said confuses you, go back to the article
What
is ASP?
Now
that is out of the way. Let's begin.
Part 1:
Create My First ASP Page
START YOUR PAGES
Open your favorite text or HTML
editor. It can be FrontPage, NotePad, FireWorks, Arachnophilia, etc... It
don't matter.
Start off with your basic HTML
page with any colors and such that you want but save the page as
first_asp_page_part1.asp
|
<html>
<head>
<title>My
First ASP Page</title>
</head>
<body
bgcolor="#FFFFFF"
text="#000000" link="#003300"
vlink="#006600" alink="#689577">
</body>
</html> |
STARTING AND ENDING ASP SCRIPT
Now we will start writing actual ASP scripts.
To start ASP you have to use
<%
and likewise to end ASP
codes you use %>
Simple Right?
COMMENTS
My first major rule in
ASP coding to is leave yourself notes, so you if you come back later, you know
what that part of the codes does. This has always been proper programmer
etiquette.
In ASP, this is called A "Comment".
To initiate a comment, use the apostrophe mark followed by your comments.
Comments can only be used inside ASP brackets. Otherwise, it will be displayed
on the page as HTML coding.
<%
'My
Comment is inside the ASP brackets
%> |
DIMENSIONING VARIABLES AND COMMENTING
Many times later in your ASP
progress you will use variables which you can define to be anything. Unlike
VBScript on your computer, the newer ASP servers do NOT required variables to be
dimensioned. However, using the dimension function allows you to add comments
about that variable.
There are some predefined variables
as well.
Let's start by Dimensioning our variables.
Let's do a variable called MyVariable to hold some information. You can
call it anything you want.
And using what we learned above, we
will add a comment to remind us later what that variable is exactly. In large
applications, the becomes very useful when going back and trying to work on the
code.
|
<%
'Dimension
variables
Dim
MyVariable 'Comment
on what this variable holds |
Notice I haven't given the variable
MyVariable
a
data type as you may traditionally do in VB programming. This is because VBScript only has variant as a data type.
GIVE A VARIABLE A VALUE
Now that we have a variable, Let's define it to be some text. You could of
course define to be anything other than just text. Later you will learn how to
get data out of databases and etc...
DISPLAY A VARIABLE USING RESPONSE.WRITE Now that the variable has a value, to display it, we will use the
Response.Write statement. I have used this statement thousands of times in my
ASP Programs.
You can use Response.Write to also insert normal HTML codes will in the middle
of an ASP script. Let's go back, and add some html before our variable to add
lines and a font style and size.
However, usually font tags begin
<font style="verdana" size="1"> but you can't use "
because that will denote the end of Response.Write so there are two ways to fix
this problem.
Double Quotes "" or use an
apostrophe mark '. I will show you both.
Let's go back, and add some html
before our variable to add lines and a font style and size.
|
'Start a font tag
and use double quotes
Response.Write ("<font face=""Arial"" size=""2"" color=""#000000"">")
Write
MyVariable to the web page
Response.Write (MyVariable)
'End a font tag
Response.Write ("</font>")
|
|
<html>
<head>
<title>My
First ASP Page</title>
</head>
<body
bgcolor="#FFFFF" text="#000000"
link="#003300" vlink="#006600"
alink="#689577">
<%
'Dimension
variables
Dim
MyVariable 'Comment on what this variable holds
'Write
line breaks into the web page
Response.Write ("<br><br>")
'Start a font tag
and use double quotes
Response.Write ("<font face=""Arial"" size=""2"" color=""#000000"">")
'Write
MyVariable to the web page
Response.Write (MyVariable)
'End a font tag
Response.Write ("</font>")
'Close the server script %>
</body>
</html> |
|