ASP Object Example - Passing Values between Pages

This section provides a tutorial example on how to pass values from one page to another. This example is a very simple registration application with two ASP pages.

There are many ways to pass values from one pages to the next pages:

In the following example, I have two ASP pages working together as a registration process. Here is the fist ASP page, reg_form.asp:

<script language="vbscript" runat="server">
'  reg_form.asp
'- Copyright (c) 2015,, All Rights Reserved.
'  This ASP page presents a registration form, and collects the input
'  data.
  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=" & _
    ' Presenting the registration form 
    response.write("<b>Registration Form</b>:<br>")
    response.write("<form action=reg_form.asp method=get>")
    response.write("Firt 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("<input type=text size=32 name=email><br>")
    response.write("<input type=text size=32 name=url><br>")
    response.write("<input type=submit name=submit value=Submit><br>")
    response.write("Your session ID is " & session.SessionID & "<br>")
  end if

Here is the second ASP page, reg_done.asp:

<script language="vbscript" runat="server">
'  reg_done.asp
'- Copyright (c) 2015,, All Rights Reserved.
'  This ASP page confirms a registration.
   ' Save the data here
   response.write("<b>Thank you registrating with us</b>:<br/>")
   response.write("Firt Name:")
   response.write(application("first_name") & "<br/>" & vbNewLine)
   response.write("Last Name:")
   response.write(request.QueryString("last_name") & "<br/>" _
      & vbNewLine)
   response.write(session("email") & "<br/>" & vbNewLine)
   response.write(session("url") & "<br/>" & vbNewLine)
   response.write("Your session ID is " & session.SessionID & "<br/>")

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

Firt Name: Bill
Last Name: Smith

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

Thank you registrating with us:
Firt Name:Bill
Last Name:Smith
Your session ID is 42285894

A couple of interesting notes:

Table of Contents

 About This Book

 Introduction of VBScript - Visual Basic Scripting Edition

 Variant Data Type, Subtypes, and Literals

 Arithmetic Operations

 Numeric Comparison Operations and Logical Operations

 String Operations - Concatenation and Comparison

 Variable Declaration and Assignment Statement

 Expression and Order of Operation Precedence

 Statement Syntax and Statement Types

 Array Data Type and Related Statements

 Array References and Array Assignment Statements

 Conditional Statements - "If ... Then" and "Select Case"

 Loop Statements - "For", "While", and "Do"

 "Function" and "Sub" Procedures

 Built-in Functions

 Inspecting Variables Received in Procedures

 Error Handling Flag and the "Err" Object

 Regular Expression Pattern Match and Replacement

 scrrun.dll - Scripting Runtime DLL Library

 Creating Your Own Classes

 IE Web Browser Supporting VBScript

IIS ASP Server Supporting VBScript

 What is ASP (Active Server Pages)?

 Static, Client-Side and Server-Side Scripting Pages

 Setting Up IIS to Run ASP Pages - asp.dll

 ASP Objects: Request, Response, Session and Application

ASP Object Example - Passing Values between Pages

 Interacting with External Applications - ActiveX Data Object (ADO)

 WSH (Windows Script Host)


 PDF Printing Version