Passing Values between Pages

This section provides a tutorial example on how to pass values from one ASP page to another using the 'session' object.

There are 3 ways to pass values from one page to the next page:

In the following example, I have two ASP pages working together as a registration process and using "session" object to pass data across pages. Here is the fist ASP page, reg_form.asp:

<script language="vbscript" runat="server">
'  reg_form.asp
'  Copyright (c) 2002 by Dr. Herong Yang
'  This ASP page presents a registration form, and collects the input
'  data.
'
   response.write("<html><body>")
   submit = request.QueryString.Item("submit")
   if submit = "Submit" then
      ' Collecting the input data
      session.Contents("url") = request.QueryString("url")
      session("email") = request.QueryString("email")
      application("first_name") = request.QueryString("first_name")
      response.Redirect("reg_done.asp?last_name=" & _
         request.QueryString("last_name"))
   else
      ' Presenting the registration form 
      response.write("<b>Registration Form</b>:<br/>")
      response.write("<form action=reg_form.asp method=get>")
      response.write("First Name:")
      response.write("<input type=text size=16 name=first_name><br/>")
      response.write("Last Name:")
      response.write("<input type=text size=16 name=last_name><br/>")
      response.write("Email:")
      response.write("<input type=text size=32 name=email><br/>")
      response.write("URL:")
      response.write("<input type=text size=32 name=url><br/>")
      response.write("<input type=submit name=submit value=Submit></br>")
      response.write("</form>")
      response.write("Your session ID is " & session.SessionID & "<br/>")
   end if
   response.write("</body></html>")
</script>

Here is the second ASP page, reg_done.asp:

<script language="vbscript" runat="server">
'  reg_done.asp
'  Copyright (c) 2002 by Dr. Herong Yang
'  This ASP page confirms a registration.
'
   response.write("<html><body>")
   ' Save the data here
   response.write("<b>Thank you registrating with us</b>:<br/>")
   response.write("First Name:")
   response.write(application("first_name") & "<br/>" & vbNewLine)
   response.write("Last Name:")
   response.write(request.QueryString("last_name") & "<br/>" &vbNewLine)
   response.write("Email:")
   response.write(session("email") & "<br/>" & vbNewLine)
   response.write("URL:")
   response.write(session("url") & "<br/>" & vbNewLine)
   response.write("Your session ID is " & session.SessionID & "<br/>")
   response.write("</body></html>")
</script>

Request reg_form.asp with IE, and fill in the form with:

First Name: Bill
Last Name: Smith
Email: bill@smith.com
URL: www.smith.com

Then click the Submit button, you will get the output of reg_done.asp:

Thank you registrating with us:
First Name:Bill
Last Name:Smith
Email:bill@smith.com
URL:www.smith.com
Your session ID is 42285894

A couple of interesting notes:

Table of Contents

 About This Book

 ASP (Active Server Pages) Introduction

 IIS (Internet Information Services) 5.0

 MS Script Debugger

 VBScript Language

 ASP Built-in Run-time Objects

ASP Session

 What Is Session?

 Properties and Methods of the "session" Object

Passing Values between Pages

 HTTP Communication Level Debugging

 HTTP Communication Log Example

 Creating and Managing Cookies

 Managing Sessions with and without Cookies

 scrrun.dll - Scripting Runtime DLL

 Managing Response Header Lines

 Calculation Speed and Response Time

 ADO (ActiveX Data Object) DLL

 Working with MS Access Database

 Guest Book Application Example

 References

 Full Version in PDF/EPUB