Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with Session Variables Between Pages

Status
Not open for further replies.

Aamin

Programmer
Oct 2, 2002
18
0
0
CA

This is what i have:

(from page1.asp...)

<%
for i = 0 to (session("icount") - 1)
response.write("<tr>")
response.write("<td><a href='page2.asp')> ")
response.write(companyname(i) + "</a></td>"
next
%>

The user will be presented with a list of companies. WHen the user clicks on a company name, they will be directed to page2.asp.
I have a session variable Session("ID") that needs to be populated with the ID of the corresponding company name that is clicked by the user. Page2.asp needs to process Session("ID") so that it can display information from the DB relating to the compnay that was selected.
How do I store the corresponding ID when the user clicks on a link from the list?

 
use a form post/get or use hrefs with querystrings built into them , request the querystring value from page2, and use it appropriately including assigning it to your session value you're desiring, or you can have the href point to a target ="_blank" that does the same thing and JS closes itself and/or opener.refresh after assigning the session value.

[thumbsup2]DreX
aKa - Robert
 
Hey DreX, thx for your help.

How do I incorporate querystrings into Hrefs exactly?
 
<a href="page2.asp?company=1">
? is the beginning of querystring, company is the element ( can be named whatever ) and 1 is the value, as for asp side you can :

<a href="page2.asp?company=<%=selectedcompany%>">

[thumbsup2]DreX
aKa - Robert
 
FROM PAGE1.ASP:
...
...
if session("icount") > 1 then
'Populate Arrays from Search page
companyname = session("companyname")
searchaddress = session("searchaddress")
SITEID = session("id")
prov = session("prov")
city = session("city")
'Create Table
response.write("<tr>")
response.write("<td>")
response.write("<table cellpadding='0' cellspacing='0'
border='0' width='650'>")
'List each company and allow the user the choose which
profile they want to view
for i = 0 to (session("icount") - 1)
response.write("<tr>")
response.write("<td><a href='page2.asp?
txtSiteId=SITEID(i)'>")
response.write(companyname(i) + "</a></td>" + "<td
class='results'>" + searchaddress(i) + "</td><td
class='results'>" + city(i) + "</td><td
class='results'>" + prov(i) + "</td>" )
next

response.write("</table>")
end if
...
...

FROM PAGE2.ASP:
...
...
<%
if (request.form("txtSiteId") <> "") then
session("SiteId") = request.form("txtSiteId")
end if
%>
<%
Dim rsSearch
'Find record so that the company details can be
displayed
Set rsSearch = Server.CreateObject("ADODB.Recordset")
rsSearch.ActiveConnection = MM_objConn_STRING
rsSearch.Source = "SELECT * FROM Sites WHERE SiteId
= '" + session("SiteId") + "'"
rsSearch.CursorType = 0
rsSearch.CursorLocation = 2
rsSearch.LockType = 1
rsSearch.Open()
%>
...
...

PROBLEM:
When I attempt to create the recordset (rsSearch), I get nothing becuz Session("SiteId") is returning NULL.
What am i doing wrong?
 
Try seeing if request.form("txtSiteId") actually contains any data by response.write(request.form("txtSiteId")).

Also try:
Code:
<%
if not isnull(Trim(request.form("txtSiteId")) or Trim(request.form("txtSiteId")) <> "" then
  session("SiteId") = request.form("txtSiteId")
end if
%>

- FateFirst
 
On page2.asp check the address bar to see whether txtSiteId actually has been given a value from the href you create on page1.asp (see below).

<a href='page2.asp?txtSiteId=SITEID(i)'>

- FateFirst
 
OK here is the mistake you are doing:

on page you are doing this:

response.write("<td><a href='page2.asp?
txtSiteId=SITEID(i)'>")

that is you are passing tstSiteId as a queryString

On page 2

if (request.form("txtSiteId") <> "") then
session("SiteId") = request.form("txtSiteId")
end if

you are retrieving it as a form variable...

do this instead

if (request.QueryString("txtSiteId") <> "") then
session("SiteId") = request.QueryString("txtSiteId")
end if

-VJ

 
rofl!!! (laughing at myself)

I didnt even notice that....runs 'n' hides!

- FateFirst
 
OK, another question:

In this statement,

<a href='page2.asp?txtSiteId=SITEID(i)'>

is the querystring element being populated when the page first loads or when user clicks on the link?
My goal is to populate the element when the page is loaded so that each company that is listed has a siteid attached to it. For example, let's just say these companies are listed:

Company1 (2343243289)
Company2 (2342311322)
Company3 (4345345345)
Company4 (5463456333)

The ID's won't show but as we're going through the FOR LOOP i want to attach the corresponding ID's to each company from the array SiteId(i) (which was created from a search validation page prior to executing page1.asp), so that if the user decides to select "Company2" the ID "2342311322" will be passed over to page2.asp which needs to create a recordset and display info relating to "Company2".

Is this possible or do I need to employ an alternative method?
 
First things first...

<a href='page2.asp?txtSiteId=SITEID(i)'>

in the above line of code the variable txtSiteId gets populated with the appropriate value only when the user clicks...

Now for the second question...

You said you want to populate the page with the respective company code...How are you going to base this...

I mean on what condition the user gets the page in which when he click the above link he get the company 2 code populated???

please provide more information to get correct replies...

-VJ

 
I have a current web application that utilizes a login to authenticate users
into the application. Once I authenticate them, I store away the user's
name in a Session variable. I then utilize this check to confirm the
session has not timed out (isLogon.asp - which I include on every page).

if Session("user") = "" then
call setURL()

Response.Redirect "login.asp"
end if

function setURL()
Session("TargetPage") = Request.ServerVariables("PATH_INFO")
Session("QueryString") = Request.ServerVariables("QUERY_STRING")
end function

I then utilize this function to upon login return the user back to where
they left:

function getURL()
dim url

if Session("TargetPage") <> "" then
url = Session("TargetPage")

if Session("QueryString") <> "" then
url = url & "?" & Session("QueryString")
end if
end if

getURL = url
end function

This all assuming using the "get" method on forms - which was fine given the
limited data being collected on the form.

A new requirements has been given that will require lots of data (well over
the QueryString limits). So seems I need to go to the "post" method on my
forms. However, with this method how do I ensure I return the user to the
appropriate location upon a session timeout??

Any pointers would be most appreciated.

BBB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top