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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problems with session variable

Status
Not open for further replies.

rtnMichael

Programmer
Aug 5, 2002
152
US
hey,
I have some session variables being declared at the top of some pages. Maybe it's easier to show code:

Page 1: set up forms and variable names for page 2

Page 2:
(up on top of page)
session("program") = request.form("program_name")
session("email") = request.form("txtEmail")
session("database") = request.form("database_name")
etc....

page 3:
session("test_type") = request.form("test_type")

page 4:
Email: <%Response.write session(&quot;email&quot;)%>
Program:<%Response.write session(&quot;program&quot;)%>
Database:<%Response.write session(&quot;database&quot;)%>
Test Type:<%Response.write session(&quot;test_type&quot;)%>

I place a button to add other things on page 4 to send to page 5

page 5 has the option to add other things or just to submit as is. At this point is the problem. The &quot;cancel&quot; button will take you back to the previous page, but with the &quot;test type&quot; area blank. The code is the same for each entry, but only the &quot;test type&quot; is gone.

can someone help me, I can't seem to see what the problem is.

Thanks
M
 
Do this:

Session(&quot;test_type&quot;) = Request(&quot;test_type&quot;)

And, when you go back to a page, add the querystring vars like this:

Response.Redirect(&quot;test_type.asp?test_type=&quot; & Session(&quot;test_type&quot;))

If you take out the .Form in all of your Request.Form calls, then it will first check the Form, then the Querystring. This way, if you have one, you're good. Just don't get into doing this often - it can lead to buggy software if you don't keep track of all of your vars. ________________________________________
Michael C Flanakin
Indigo Web Systems
michael.flanakin@indigows.com
 
ok, I was messing around with what you told me to put, and I guess I'm not doing it right. I put it in the onclick part of the button...just the code. Then I put it in a function, still no progress. I've tried a numerous amount of different ways, and still can't get it.

What confuses me most is that one of the times I tried it, I ended up with the session variable printing out to the page, and it wasn't blank!!! I'm assuming it's still there, but just not printing out.

Maybe it's just the way I'm doing it, but the variable gets hidden when it returns to the previous page.

BTW at least I did the request(&quot;test_type&quot;) thing right! ;-)
 
Well, if you're successfully saving a session var's value, then it will not change until you set it again, so, if you go back to a page, technically you are writing over it. If you do not want to do this, check to see if it is null before saving it.

If Session(&quot;this_var&quot;) = &quot;&quot; Then
Session(&quot;this_var&quot;) = &quot;new value&quot;
End If

I'm not totally sure what you're going for, but this may be why it was not blank when you expected it to be. ________________________________________
Michael C Flanakin
Indigo Web Systems
michael.flanakin@indigows.com
 
let's see if I can say this without fumbling up.

I have a test_type page getting the session(&quot;test_type&quot;) from the previous page's form. It prints out just fine.

Then I have two buttons at the bottom, a 'submit' and an 'add'. The submit takes you to the &quot;Add Exclusions&quot; page.

The Add Exclusions page has two buttons, a 'submit' and a 'cancel'. In the onclick for the cancel I have
&quot;history.go(-1)&quot;, which I would assume is like hitting the back button. Then the submit button's onclick simply has a form.submit(). The submit button will take me back to the test_type page with the added exclusions (supposedly!!!). That's where I lose the test_type variable. I have even tried your approach and added

if session(&quot;test_type&quot;) = &quot;&quot; Then
session(&quot;test_type&quot;) = request(&quot;test_type&quot;)
end if

Unless this isn't right, It doesn't work.

I have a question...if the form I'm submitting in the exclusion page doesn't have a test_type variable, will the test_type page try reading that variable and when it finds out it's not there, just wipe it out?

I hope I haven't confused you, I know I am.

Thanks
M
 
ok, label me stupid!!! (-:

I was messing around with the form pages in the exclusion page, and I forgot I put another page in yesterday. Your suggestion worked and I'm up and running.

Sorry for the confusion and thanks for the help

M :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top