| the complete webmaster | ||||
| tutorials | reviews | reference | ||
|
A Simple ASP WalkthroughA lot of people are asking for more on ASP. So, being the kind and generous person that I am, I spent all morning designing a "simple" ASP demo, and I'm going to walk you through the design process. I used FrontPage 98, as it is especially "friendly" to ASP, with and exception or 2, and we will encounter one such exception here, and find out how to deal with it. This demo consists of 2 pages, one normal HTML page containing a form, and an ASP page which receives the results of the form entries and displays a "personalized" page. Here is what the first page looks like:
As you can see, there is a text box, whose name, appropriately, is "name." There are 2 radio button groups, "sex" (yes, please!) and "color." The ACTION property of this form points to "welcome.asp." And that is the page I'm going to walk through with you. The first step was getting the values from the form and assigning them to variables. I did this by inserting the following asp code in the <head>: <head><title>Welcome</title> <meta name="GENERATOR" content="Microsoft FrontPage 3.0"> <% name = Request.Form("name") sex = Request.Form("sex") color = Request.Form("color") %> </head> The ASP tag is identified by the following symbols: <% (begin) and %> (end). We assgn the form values by using the "Request" object. It has a property called the "Form" object. To access the value of a "Form" object's parameter values, you simply refer to "Request.Form("parametername"). Note the quotes around the parameter name. Now we have 3 global variables to work with. It is a lot easier to write "name" than writing "Request.Form("name") over and over again, don't you think? Next, we're going to write our welcome message. I started by typing it in normally, with my own name and the word "Mr." :
Then I replaced the word "Mr." with an ASP script, as well as my name. I started by highlighting the "Mr." (see below) then clicked the "Insert Script" button on the toolbar.
Here's the dialog box I used to create the "Sex" part of the message:
Note the fact that I have checked the "Run Script at Server" box. This creates the ASP tag. I did the same with the "name" part of the message, using the following code: "Response.Write name" The "Response" object is used mainly for writing HTML to the page. Afterwards the page looked like this, in FrontPage Editor:
All that remains is the hard part. What I wanted to do was to customize the background color and text color according to the favorite color chosen by the user. To do this, I had to create the <body> tag dynamically. However, this isn't as easy as it seems. FrontPage Editor won't allow you to have more than one <body> tag. If you simply put a bunch of scripts with if/elseif/else tags in the page, with a bunch of body tags, FrontPage Editor will remove all but the first <body> tag. Now you see why I wanted to create all the HTML first! The solution is to save and close the page, then open it in a text editor for the final blow. And never open it in FrontPage Editor again! Here's the code as it appears in a text editor: <head> <%if color =
"blue" then%> I got the background color values by changing the "Page Properties" in the dialog box before I closed the page, and copied the color values after selecting them with the color picker. The results were fairly cool:
Hopefully, I will be able to post the working demo on my website at http://www.connectrans.com/takempis within the next week, but for now, I have family to visit for the holidays! See you next week.
Author: Kevin Spencer More articles about Microsoft
FrontPage |
| write for us | about us | advertise |
Copyright 1997, 1998 A Big Lime. All rights reserved.