|
Putting It All Together.
The ASP
Part 2 course examines all the
ASP Objects in detail. This lesson briefly previews the Request and Response
Objects.
Please read, outline and paraphrase chapter seven of the course
textbook. In this exercise, you'll learn how to submit and process form data
and selectively display it on a confirmation page.
To experience the
true power of ASP, it's highly recommend taking the Part 2 and Part 3
classes where you'll learn techniques like writing HTML form data to a text file or
updating a database with customer information. The Part 1 course simply
surveys ASP and introduces basic concepts. Part 2 and Part 3 delve deeper into
ASP, examining coding techniques and developing best practices.
|
Module 4.1
The primary difference between the QueryString Collection and the Form
Collection is that QueryString gets appended to the URL with a question
mark via the Get Method while Form gets sent within the HTTP
request via the Post Method.
|
Request Object.
Used by the client (visitor) to request information from the web server.
It encapsulates client-requested information as a package for use by the server.
The Request Object has five collections
(or parts):
1. QueryString - Sends values submitted from an HTML form within the
URL. Can be generated in four ways: (1) Anchor tag, (2) Get Method,
(3) HTTP address and (4) Response.Redirect Method.
2. Form - Sends values submitted from an HTML form within the HTTP
request body via the Post Method.
3. ServerVariables - Holds HTTP headers that contain
information such as browser type or referring page name as well as information
about the server.
4. Cookies - Identify and mark a client entering a web site by storing
information on the client's computer that is used by a particular server to
(1) personalize web pages, (2) determine where the client has been and (3)
keep clients updated on information.
5. ClientCertificate - This collection stores digital certificates
exchanged between the visiting client and the server.
See also chapter seven and the Appendix in the course textbook.
|
Module 4.2
*ASP
processing is held within the HTML Output Stream that is sent to the
client when complete.
|
Response Object.
Used by the web server to send output in response
to the client's (visitor) information request.
Some notable methods and properties are:
1. Write Method - Two techniques for sending information back to the client:
(1) Response.Write and (2) the shortcut, <%=
%>.
2. Buffer Property - Allows for manual control of the HTML Output
Stream*. Its Flush Method immediately sends everything within the
buffer to the client. Its Clear Method erases HTML already within the
buffer except response headers. Its End Method stops the server from
processing the ASP script and sends the remaining buffer output to the client.
3. Expires and ExpiresAbsolute Properties - Expires
specifies in minutes how long a web page should be cached. ExpiresAbsolute
works like Expires but is for periods longer than minutes, and it sets the
date and/or time a cached web page expires.
4. Redirect Method - Informs the browser to retrieve a different web
page within the same web site or on a completely different web site.
See also chapter seven and the Appendix in the course textbook.
|
Module
4.3
|
Exercise 4.
Open the Part1 folder in
Windows Explorer > right click > New > Text
Document > name it FormSubmitEx4.asp > Yes (make
certain the file has the .asp extension rather than the .txt
extension). Copy and paste the following text into FormSubmitEx4.asp:
<HTML><HEAD><TITLE>FormSubmitEx4</TITLE></HEAD><BODY>
<%
'-----------------------------------------------------------
'This application submits an
HTML form and displays its
'data on a confirmation page
using the Form Collection.
'
'Created: 08/27/2000, By:
Instructor, Revised: 08/27/2000
'-----------------------------------------------------------
%>
<FORM
NAME=Hotel ACTION="FormConfirmEx4.asp"
METHOD="POST">
First Name: <INPUT
TYPE="text"
NAME="FirstName"<BR><BR>
Last Name: <INPUT
TYPE="text"
NAME="LastName"><BR><BR>
Enter Number
of Rooms Reserved:
<INPUT
TYPE="text"
NAME="RoomsReserved"><BR>
Enter Number of Nights at the Hotel:
<INPUT
TYPE="text"
NAME="HotelNights"><BR><BR>
<INPUT
TYPE="submit"
VALUE="Submit">
<INPUT
TYPE="reset"
VALUE="Reset">
</FORM></BODY></HTML>
|
Save this as FormConfirmEx4.asp in
the Part1 folder.
<HTML><HEAD><TITLE>FormSubmitEx4</TITLE></HEAD><BODY>
<%
'-----------------------------------------------------------
'This application submits an
HTML form and displays its
'data on a confirmation page
using the Form Collection.
'
'Created: 08/27/2000, By:
Instructor, Revised: 08/27/2000
'-----------------------------------------------------------
'It is good programming practice to first assign all the form values to
variables.
varFirst=Request.Form("FirstName")
varLast=Request.Form("LastName")
varNights=Request.Form("HotelNights")
varRooms=Request.Form("RoomsReserved")
%>
<BR>Thank
you <B><%=varFirst%></B>
for contacting us.<BR>
<BR>You have reserved <B><%=varRooms%></B>
rooms for <B><%=varNights%></B> nights
at the Hotel California.<BR>
</FORM></BODY></HTML>
|
When
you submit the information on the HTML form, you should get a personalized
confirmation page. Try the same exercise above using the QueryString
Collection.
Hint: Simply switch from the Post Method to the Get Method
and replace all occurrences of Request.Form with Request.QueryString.
See the course textbook for help.
|
Module
4.4
|
Exercise 4 Continued.
- Visit all the links shown in this lesson and define
any new vocabulary terms using the course textbook and the VBSLR.
- Read, paraphrase and outline chapter seven of
the course textbook.
- Take notes on this week’s materials and paraphrase it in
your own words. Don't forget to take all the quizzes and click the grade
button. Before the end of this month, you need to complete the exit
survey to learn your final course grade.
|
Module
4.5
|
Quiz 4.
Hint: All the answers are found on this page,
but please still read chapter seven.
- Which of the following may generate the QueryString
Collection?
- What is the main difference between the QueryString
Collection and the Form Collection?
- In ASP, cookies are used to?
- What does the HTML Output Stream hold?
- Redirect is a method of which object?
|
Module
4.6
|
Conclusion.
- We have learned about writing HTML dynamically,
working with arrays and include files, ASP objects and submitting and
processing HTML forms.
- We have discovered several online resources
including the VBScript
Language Reference, the HTML
Validator, the BareBones
Guide to HTML, the ZDWebopedia
and the TechWeb Encyclopedia.
- Remember, just as it took lots of time and practice
to learn all the attributes and properties of HTML tags, so will be the
case for the Properties, Methods, Events and Objects of ASP.
- To
experience the true power of ASP, it's highly recommend taking the Part 2
and Part 3 classes where you'll learn techniques like writing HTML form data
to a text file or updating a database with customer information. Part 2 and Part 3
delve deeper into ASP, examining coding techniques and developing
best practices. Congratulations
on making it this far! Learn more in ASP Part 2. J
|