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

Sections:
Sample Chapters
Commonly Asked Message Board Questions
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
XML Info
Information:
Feedback
Author an Article
ASP ASP.NET ASP FAQs Message Board Feedback
Print this page.
Published: Tuesday, April 13, 1999

Four Ways to Send/Get Information
From one ASP Page to Another
By Joćo Vieira


Passing variables from one page to another is an important task in ASP. Correctly passing information among Active Server scripts was one of my biggest problems when I started some more advanced web programming projects a couple of years ago. What I will show in this article is ways to send a variable (it's name and data) from one ASP/HTML page to another ASP page.

- continued -

'

In my example, I will use two variables: name and phone. At this first example we use the GET method, this one will show all the information on the link address, like
http://www.anything.com/getting.asp?name=namevalue&phone=phonevalue

FILE : SENDING.HTML

<form name="sending" method="GET" action="getting.asp" target="_self">
    </FONT><font size="2">Name :</font><br>
    <input name="name" size="22" >
    <br>
    <font size="2">Phone:</font><br>
    <input name="phone" size="14" >
    <br> 
    <input type="submit" value="Send" name="Send">
</form>

FILE : GETTING.ASP

<%
    'the querystring gets the info that it is
    'attached at the link address
    gotname = Request.querystring("name")
    gotphone = Request.querystring("phone")
%>

Here I use the POST method, the one I use most, its more confidential and doesn't show the variable's content.

FILE : SENDING.HTML

<form name="sending" method="POST" action="getting.asp" target="_self">
    </FONT><font size="2">Name :</font><br>
    <input name="name" size="22" >
<br>
    <font size="2">Phone:</font><br>
    <input name="phone" size="14" >
    <br> 
    <input type="submit" value="Send" name="Send"> </form>

FILE : GETTING.ASP

<%
    'the request.form gets the info within the boxes of the form actioned
    'from the previous HTML/ASP
    gotname = Request.form("name")
    gotphone = Request.form("phone")
%>

Here i use something like the first example, the big difference is that you say wich variables to send.

FILE : SENDING.ASP

<%
    name2 = "The name I want"
    'or name2 = recordsetobject("name"). Yes you can get info from DB
   phone2 = "1232131221"
%>

    <a href="getting.asp?name=<%=name2%>&phone=<%=phone2%>" target="_self" >
        <img src="images/button_gotogetting.gif" name="pic">
    </a>

FILE : GETTING.ASP

<%
    gotname = request.querystring("name")
    gotphone = request.querystring("phone")
%>

In the above approach you make a button, or an image. The image is hyperlinked so that the link contains the information you want to send.

The last example of passing data from one ASP page to another is through using session variables. Session variables can be very useful, they are similar to global variables. While you're browsing between the pages the variable exists; you don't have to explicitly pass it from one page to the next. Of course, there are disadvantages to using Session Variables. There is a nice article explaining the Pros & Cons of Session Variables on 4Guys.

FILE : SENDING.ASP

<%
    session("name") = "Myname"
    session("phone") = "21121231"
%>

<a href="getting.asp" target="_self" >
    <img src="images/button_gotogetting.gif" name="pic">
</a>

FILE : GETTING.ASP

<%
    gotname = session("name")
    gotphone = session("phone")
%>

Those are the four ways with which you can pass data from one ASP page to another!


João Vieira BIO: (email me!)
- Age : 23
- Student And worker (tryin' to finish university, on the last year of the graduation)
- Workin' now at NetGate Portugal
- Programming little stuff since 1989
- Programming HTML since 1996
- Programming JavaScript since 1997, made some experiences with Java.
- Programming ASPs since the Summer of 1997 (yeap, I didn't had nothing to do. Now I love it.)
- Programming ActiveX since 1998
- Webmaster of www.joaovieira.com



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