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

Why does this code kill all my session variables

Status
Not open for further replies.

frogggg

Programmer
Jan 17, 2002
182
US
I have the following code in an include file to check if the user logged in or not. For some reason, whenever a page requires session variables being set in an onClick event, this code kills them, and they don't show up on the next page.
Does anyone know why and what I can do so I can have this code and my session variables too?! (some cake would be nice too)

<%
if session(&quot;CandID&quot;) <> &quot;&quot; then
dim helloString
helloString = &quot;Hello &quot; & session(&quot;CandID&quot;) & &quot;!&quot;
helloString = helloString & &quot;If you are not &quot; & session(&quot;CandID&quot;) & &quot;please &quot;
helloString = helloString & &quot;<a href='default.shtml'>log in.</a>&quot;
Response.Write helloString
else
%>


<h3>Already a member? <br>Login now.</h3>
<form action=&quot;validatePassword.asp&quot; method=&quot;get&quot; name=&quot;frmLogin&quot;>

<table>
<tr>
<td>Username: </td></tr>
<tr>
<td><input id=&quot;text1&quot; name=&quot;txtUserName&quot;></td></tr>
<tr>
<td>Password: </td></tr>
<tr>
<td><input type=&quot;password&quot; id=&quot;password1&quot; name=&quot;txtPassword&quot;></td></tr>
</table>
<input type=&quot;image&quot; src=&quot;images/img_Submit.gif&quot; value=&quot;Submit&quot; id=&quot;submit1&quot; name=&quot;btnSubmit&quot; WIDTH=&quot;106&quot; HEIGHT=&quot;54&quot;>
</form>

<h3>New User? <a href=&quot;profile.shtml&quot;>Click Here</a> </h3>
<%
end if
%>

 
i see no reason why this code would erase your session variables... could the problem be somewhere else?
 
Okay, some more specifics-
The session variable assignments are located in a server side event handler of a dtc button. The code is as follows:

<script ID=&quot;serverEventHandlersVBS&quot; LANGUAGE=&quot;vbscript&quot; RUNAT=&quot;Server&quot;>
Sub btnSubmit_onclick()

session(&quot;Location&quot;) = Request.Form.Item(&quot;lstLocation&quot;)
Response.Write session(&quot;Location&quot;)
session(&quot;JobCategory&quot;) = Request.Form.Item(&quot;lstJobCategory&quot;)
Response.Redirect &quot;displayJobs.asp&quot;
End Sub

</script>

When the include mentioned in the first post is included in the current page, these session variables are blank on the following page. If it is not, and even if it's included in the following pages, the session variables are fine.

Anyone know what's going on?

Thanks in advance!
 
To make sure you aren't overwriting your Session variables when you include code, try something like this:

Sub btnSubmit_onclick()

If Len(Session(&quot;Location&quot;))=0 then
session(&quot;Location&quot;) = Request.Form.Item(&quot;lstLocation&quot;)

end if
Response.Write session(&quot;Location&quot;)
if Len(Session(&quot;JobCategory&quot;))=0 then
session(&quot;JobCategory&quot;) = Request.Form.Item(&quot;lstJobCategory&quot;)
end if
Response.Redirect &quot;displayJobs.asp&quot;
End Sub
 
I understand what must have happened - when the page gets called again by the include the form values are empty/nonexistant and that's what gets put in the session variables. It sounds like it makes a lot of sense - but it still doesn't work.

Also, I don't have a problem when I just include a .htm, only when I include a .asp. If that helps solve the mystery.
 
Hi frogggg
this is a shot in the dark but can you check where exactly the page is going to.
the form seems to submit to validatepassword.asp and you seem to be redirecting to displayjobs.asp.
Could this be the problem? if not, sorry for wasting your time!!
REGARDS
10091976
 
Well, I'm working in VI, first of all. The include file represents a check if the user is logged in - if yes, hello Username. if not, login box. The login box will submit to validatePassword.asp. The page is redirecting to displayJobs.asp but the session variables are empty.
That's the scoop.
Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top