The Session Object

Reading Form Data

In this exercise, you will create an ASP that reads data supplied by an HTML form and saves it in the Session object.

You will save the data in the Session object for use by other pages of the fictional State University Web site.

* To add files to a project in Visual InterDev

  1. Start Visual InterDev.
  2. From the File menu, click New .
  3. From the Projects tab, select Web Project Wizard .
  4. Name the project StateU , and set the directory to WA\Practice\Ch10\StateU . Click OK .
  5. Leave the default Server Name of localhost and click Next .
  6. Review the default entries and click Finish .
  7. From the Project menu, point to Add To Project and then click Files .
  8. From the WA\Practice\Ch10 folder, select home.asp , profile.asp , and transcript.asp . Click OK .
* To read data from the form
  1. Double-click profile.asp to open the page in the Visual InterDev Source Editor.
  2. Change the ACTION attribute of the <FORM> tag to call profile.asp.

    To change the action attribute, locate the following line of code:

     <form NAME=frmProfile ACTION= METHOD=Post> 

    Change the line of code to:

     <FORM NAME=frmProfile ACTION=profile.asp METHOD=Post> 
  3. Before the <FORM> tag, add the following server-side script:
     <% If Not (IsEmpty(Request("txtID"))) Then 'request came from Submit button on form username = Request("txtName") id= Request("txtID") major = Request("Major") 'set session variables Session("username") = username Session("id") = id Session("major") = major %> Welcome, <%=username%>, to State University. <P>I see you are interested in <%=major%>. <% End If %> <P> 
  4. Save your changes to profile.asp .
* To test the code in profile.asp
  1. Right-click profile.asp and click Preview In Browser .
  2. Type in an ID, your name, and select a major. Click Submit .
  3. What happens after the Submit button is clicked?

    Answer

* To use session data in other files
  1. Double-click profile.asp to return to the Visual InterDev Code Window.
  2. Locate the following line of code in profile.asp :
     <FORM NAME=frmProfile ACTION=profile.asp METHOD=Post> 

    Change the above line of code to the following so that a new ASP page is called.

     <FORM NAME=frmProfile ACTION=transcript.asp METHOD=Post> 
  3. Save profile.asp .
  4. Double-click on transcript.asp to edit the file in the Visual InterDev Code Window.
  5. Locate the following line of code:
     For Student ID  </font> </td> 

    Modify the above line of code to the following:

     For Student ID <%=Session("id")%> </font> 
  6. Save the changes to transcript.asp .
  7. Right-click on profile.asp and click Preview In Browser .
  8. From the toolbar, click Refresh View .
  9. Type in an ID, your name, and select a major, then click Submit .

    The Web page should read "For Student ID <<ID number>>"



Microsoft Windows Architecture Training
Microsoft Windows Architecture for Developers Training Kit
ISBN: B00007FY9D
EAN: N/A
Year: 1998
Pages: 324

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net