To read the article online, visit http://www.4GuysFromRolla.com/webtech/041399-1.shtml

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.

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!


Article Information
Article Title: Four Ways of Passing Variables Between ASP Pages
Article Author: Scott Mitchell
Published Date: Tuesday, April 13, 1999
Article URL: http://www.4GuysFromRolla.com/webtech/041399-1.shtml


Copyright 2017 QuinStreet Inc. All Rights Reserved.
Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers