When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
Related Web Technologies
User Tips!
Coding Tips

Sample Chapters
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Stump the SQL Guru!
XML Info
Author an Article
Print this page.
Passing Variables Between ASP Pages

There are many times when you will need to pass information from one ASP page to another. Often times you are collecting user input, then passing it onto an ASP page which will update or create a row in a database.

You can use HTML FORMs to send data easily from ASP page to ASP page. There are two ways of accomplishing this: you can use a FORM with a METHOD="GET" or a METHOD="POST". The METHOD of a FORM relates to how the data will be passed. If you choose GET, the data is passed through the QueryString, which means the data is passed in the string containing the URL.

No doubt you have been to site where you've entered some data and the next page has some URL which looks like:


The words following the question mark are known as the QueryString. Let's say you created a form in HTML which looked like this:

<FORM METHOD="GET" ACTION="/scripts/myfile.asp">
    Search Terms:


The user will see a text box. If they type in the word "Hello" and click on the Submit button, they will be taken to the file supplied in the ACTION keyword for the FORM. (If no ACTION is provided the current page will simply reload.)

Since we used a GET, all of the information will be in the QueryString. The QueryString, assuming I entered Hello in the textbox, will look exactly like:


If you specify your FORM as a POST, the data is still passed to the page supplied in the ACTION, but it is not sent through the QueryString. If you expect your users to be entering long, complex strings, or several (10 plus) data fields, it is usually wise to send the data through a POST form as opposed to a GET form.

Once you have sent the data, you need to read it. In the file that was specified by the ACTION tag, you can read the values into ASP variables quite easily.

All you need to do is use the Request object. It is important that you know the name of the FORM variable you are expecting. The name is denoted by the NAME field in the INPUT tag. If you'll review the code example above, we named the INPUT textbox "search". To read the value from search into a variable, all we have to do is write code like this:

    'Create a variable named SearchText
    Dim SearchText

    'Read the search form variable. We will use CStr
    'to make sure we are getting a string.
    SearchText = CStr(Request("search"))

    'Print out the value of SearchString

It's that simple to pass data from one page to another. Just the use of FORMs and use of the Request object inherent in ASP.

Happy Programming!

FAQ Table of Contents   Date Functions, Part 2 Passing Variables Between ASP Pages using POST 

ASP.NET [1.x] [2.0] | ASPFAQs.com | Advertise | Feedback | Author an Article