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!

This code is killing my session variables - WHY?

Status
Not open for further replies.

frogggg

Programmer
Jan 17, 2002
182
US
I have the following code in an onClick server side event handler:

<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>

It worked just fine, i.e. the session variables were available on the next page, until I included the following file:
<%
sub deleteVariables()
session.Contents.remove(&quot;CandID&quot;)
session.Contents.remove(&quot;UserName&quot;)
end sub

if session(&quot;CandID&quot;) <> &quot;&quot; then

dim helloString
helloString = &quot;<h3>Hello &quot; & session(&quot;UserName&quot;) & &quot;!</h3>&quot;
helloString = helloString & &quot;If you are not &quot; & session(&quot;UserName&quot;) & &quot;<br> please &quot;
helloString = helloString & &quot;<a href='default.shtml' onClick='deleteVariables()'>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><a href=&quot;profile.shtml&quot;>New Users</a> </h3>
<%
end if
%>

This code is included on all pages, but if it's included on the following page it doesn't touch the session variables. Is there something I need to know about server side event handlers that I don't? Does anyone know why this is happening?
 
Another point that may help in solving the mystery - when I include a .htm there's no problem. Only when I include a .asp.
 
You should get an error when you press the log-in link.

This lot:
<%
sub deleteVariables()
session.Contents.remove(&quot;CandID&quot;)
session.Contents.remove(&quot;UserName&quot;)
end sub

if session(&quot;CandID&quot;) <> &quot;&quot; then

dim helloString
helloString = &quot;<h3>Hello &quot; & session(&quot;UserName&quot;) & &quot;!</h3>&quot;
helloString = helloString & &quot;If you are not &quot; & session(&quot;UserName&quot;) & &quot;<br> please &quot;
helloString = helloString & &quot;<a href='default.shtml' onClick='deleteVariables()'>log in.</a>&quot;
Response.Write helloString
else
%>

is server side code. So the function deleteVariables only exists on the server, not the client - yet the log in link is expected to run a client-side version of this function. It will not find the deleteVariables function (and should error), then redirect to default.shtml.

I really think you need to attend a decent training course. (Content Management)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top