Click to See Complete Forum and Search --> : Read Variable from 2nd asp page
vkallelil
May 4th, 2001, 01:39 PM
Hi all,
I have variable declared in my first asp page
<%
Dim userId
userId=Request.form("name")
I user this userId in my queries and it works fine
%>
Now I try to use the userId in my queries, in my second asp page, and it doesn't work. I also used <!--#include file="start.asp"--> in my second asp page.
Am I doing something wrong in here. Why can my second asp page recognize the variables I declared in my first asp page??
Reggie
JoshT
May 4th, 2001, 01:57 PM
Variables declared on a page only have scope for that page. You need to use something session variables or another form of persistance.
monte96
May 4th, 2001, 11:23 PM
You can pass it with a querystring, or if your using a form that is submitted to page 2, you can write the value of UserID into a hidden textfield that will be passed with the form to the next page, then just grab it out of the request.form collection.
Sastraxi
May 5th, 2001, 06:47 PM
Adding a form to EVERY SINGLE PAGE can be a bit, uh...
TEDIOUS.
So use session variables!!!
<%
Function OutSV(Varb)
Response.Write Session(Varb)
End Function
Function ReadSV(Varb)
ReadSessionVariable = Session(Varb)
End Function
Function SetSV(Varb, Val)
Session(Varb) = Val
End Function
%>
Usage:
<%
'global.asa
SetSV "Ab","BA"
'asp1.asp
OutSV "Ab" '<---WILL DISPLAY 'BA'
%>
monte96
May 5th, 2001, 07:28 PM
Session variables are one solution, but it is at the price of scalabilty. It will work fine as long as the app never needs to grow beyond a single server. A querystring would be a solution that scales to multiple servers if needed.
I'm not arguing the value of the session object.. I use it on small scale apps that will only be used in an Intranet. But if your planning to do serious development in ASP, don't rely on it too heavily.
JoshT
May 7th, 2001, 09:05 AM
Notice how I said "session variables or another form of persistance.":D
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.