ASP_101_5288786554
ASP_101_5288786554
By Richard Rost
Published By
Amicron Computing
PO Box 1308, Amherst NY 14226 USA
www.MYOLP.com
This handbook is designed to be a supplement to the full 599CD video course for ASP 101. We
recommend you use this handbook to follow along with the class videos. This handbook is not meant as a
stand-alone study guide.
We do recommend that you watch the course videos one time through, paying attention to the lessons
covered. Follow along with the course videos using this guide. Take notes on the pages where needed.
Then, watch the videos a second time, practicing the examples yourself on your own website.
Table of Contents
Welcome ...........................................................................................................................................................................2
Table of Contents ...........................................................................................................................................................2
Introduction ....................................................................................................................................................................3
Definitions ........................................................................................................................................................................4
Our First Script..............................................................................................................................................................5
If-Then............................................................................................................................................................................12
Looping & Variables...................................................................................................................................................17
Mathematical Operatoins ..........................................................................................................................................20
If-Then-ElseIf-Else......................................................................................................................................................22
Processing Form Input ...............................................................................................................................................26
Reading the Query String..........................................................................................................................................31
Review.............................................................................................................................................................................34
We will not be discussing database connectivity in today’s class. The class follows Windows 101, 102
or 110, and HTML 101. I strongly recommend that you watch all previous classes before you start with this
class. We will be using ASP 3.0 (Windows 2000 Server, IIS 5.0), FrontPage XP, and Windows XP in
this class, but the lessons in this class are really common to all versions of Windows.
We also recommend that you take our Visual Basic 101 and FrontPage 101 classes.
If you need help locating an Internet provider that can give you a website to host your ASP pages, please
contact us. We have a list of Internet providers that offer ASP hosting.
ASP pages are simply HTML pages with a scripting language added to them to include dynamic content.
A script is a series of programming codes embedded in a web page to execute commands. For example, to
show the current date and time, or include some data value from a database.
Some scripts, like JavaScript run in the browser. These are called client-side scripts. Client-side scripts run
in the client, or the browser. The bad thing about client-side scripts is all the scripting code goes to the
user’s browser. If the user knows how to view the source of a page, he can see how the program is running.
ASP is a server-side script. The server interprets the scripts first, and then sends the page to the browser.
The browser receives only HTML. If the user were to look at the source code of the page, all he would see
is the HTML.
I’m going to click on File – and then Open Web. Then I’m going to enter my website and then click Open:
For the purpose of this class, I’m going to delete the entire header section of this page (everything from the
<head> tag to the </head> tag). All we need to concentrate on will be inside the body tags (<body> and
</body>), where I’ll type “Hello There.”
Now I’ll go back to the bottom and click on the Normal tag.
Back on the HTML tab, I want to add “The time is” and then the time after “Hello There.” Here’s how to
code that with ASP tags. Everything between <% and % > is our ASP script. This tells the server to put the
correct time there.
Let’s save this page as test.asp. ASP pages have to end in .ASP.
That’s because the server is handing out that page with the time in it. If you tried the same thing as we did
above, but did not see the time here, then your server or your site does not support ASP. You’ll have to talk
to your Internet provider.
Save the page and preview it in the browser. And there we go!
In the previous example, we had a mixture on this line of regular HTML text and ASP code.
You can have ASP generate standard text using the Response.Write command. Try this. Copy the
following onto your page.
The Response.Write command is like the old “Print” command in BASIC. The Response.Write command
makes it much easier to create dynamic lines of text. Anything inside of quotes is displayed in the browser.
It’s an actual string of text . The ampersand (&) is used to put together two strings (bits of information).
Now I’d like the computer to tell me “Good Morning” or “Good Afternoon.” Add the following to your
code below:
Let’s talk about this for a minute. DatePart is a function that will get part of the date or time. In this case
we’re saying, “Give me the H” or the hour of the current time.
The IF part is going to check and see if the date part that we get back is greater than or equal to 12. If so,
THEN print “Good Afternoon” onto the webpage.
The single quote (‘) precedes a comment. Everything after a single quote is ignored. It’s just for you or
another programmer to see and understand what you’re doing.
IF the date part is not greater than 12, the ASP script will do something ELSE. It will run the command
under the ELSE part.
As you can see, you can put almost any HTML tag inside your ASP scripts. Let’s take a look at what
exactly the server sends to the browser. On the browser menu bar, click on View – and then Source. This is
how you can see the source of any HTML page. The server replaced our ASP script with the actual values.
That’s all that’s sent to the browser.
I’d like to loop through one through five. Copy what you see below onto your own ASP page (ASP is not
case s ensitive, so don’t worry about case).
X = 1 creates a variable. While X <= 5 means that as long as X is less than or = to 5, write the value of X
(Response.write X). X = X + 1 will increment the value of X. Wend is the end of the While loop. When it
finally gets to six, it drops out.
That’s your basic While loop. Here’s another way to write the same stuff using a different loop – the For -
Next loop. Type this as your ASP code.
If we add MyValue = Round(MyValue,2) to the code, 261.11 is displayed in the web browser.
Maybe, we should have it where if it’s after 12, we can subtract 12 from the value, add some AM and PM
text, and then display that.
Now, what happens if it’s noon?! We need something to take into consideration that it could be exactly 12.
Let’s insert the following code:
That ought to do it. Let’s get rid of our fake time and un-comment the real (server) time. Save this and see
what we get.
First, let’s create a basic form. Make a new page and drop a form on it. On the menu bar, click Insert –
then Form – then Textbox.
This will give us a form with one textbox, a submit button, and a reset button.
Let’s take a look at the HTML code of this page real quick. Click the HTML tab and get rid of the header
stuff, plus the extra FrontPage gunk that we don’t need until your HTML looks like this.
Let’s give this thing a better name like, “customer” and put another one in here from Normal view. Just
copy the box and paste it after “Age”.
Save this as form-process.asp. Now go back to myform.htm and then preview it in the browser. I’ll fill in
the form with the following:
Let’s analyze this code and see what’s going on. We made a variable called Customer and we set it equal
to Request(“Customer”). ASP will request the value entered in the textbox named “Customer” from our
form. Same thing for the age. The Response.write just writes it all out.
You can specify values after a URL and you do that with a question mark and then some value, like “key”.
We’ll say, http://www.pcresale.net?key=Google. (The stuff that comes after the question mark is called the
query string.) Now I can use this URL in any hyperlinks that I advertise on Google. That way when people
come to my site, I’ll know that they came from Google.
Let’s see how I can put this in action. I’m going to create a new page in HTML view without all the header
stuff, and then type in the following ASP code. This code should get the query string and show me what it
is.
Let’s save this page as welcome.asp. Now in my web browser, I’m going to go to
http://www.pcresale.net/welcome.asp?key=hi. Our ASP page will display anything after the question mark
in our URL.
Let’s save this and see what this will do in the browser. I’ll go to
http://www.pcresale.net/welcome.asp?key=google.
Take your skills check quiz at www.599CD.COM/Test. If you pass, you can print out a Certificate of
Completion.
This document may not be used as part of a training course without express, written permission from
Amicron Computing and the purchase of an Instructional License. For details, contact:
Amicron Computing
PO Box 1308
Amherst NY 14226 USA
www.MYOLP.COM