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

Session variable not good after first page 3

Status
Not open for further replies.

rtshort

IS-IT--Management
Feb 28, 2001
878
US
I'm setting a Session variable using

Session("UserID") = Request.Form("txtUserName")

On the next page that opens, I put it in an Alert message to see if it is there. On the first page it is there, but on all other pages the alert message comes up blank.

What am I doing wrong? Rob
Just my $.02.
 
Do you have a session.abandon anywhere? I've done that before, counting active users. It never reached 2 because their was a session.abandon statement hidden in my code.
 
make sure you refernce the session when using the variable name

Session("UserID") = Request.Form("txtUserName")

response.write session("userID")

hth

Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
travmak, I do have a session.abandon in my code but it is under a button_onClick() event. I don't think it should be coming into play.

Bastien, I'm doing that as follows on page load to see if it is working:

alert (&quot;<%=Session(&quot;UserID&quot;)%>&quot;)

It works on the first page, but pages that load after the first come up with a blank alert box.

Also I have Session State enabled on IIS 5.0 under Win2K

Thanks for your replies. Rob
Just my $.02.
 
Are you calling this code

Session(&quot;UserID&quot;) = Request.Form(&quot;txtUserName&quot;)

on multiple pages? If so, you could be overwriting your value. You could try something like this:

If Len(Session(&quot;UserID&quot;))=0 then
Session(&quot;UserID&quot;) = Request.Form(&quot;txtUserName&quot;)
end if

so that if the Session already has a value, you are not trying to replace it.
 
Jaunita, I called myself checking that. I do have 2 pages that set the value. Only 1 of the 2 pages come into play per session though. The first page is the logon page. The second is the Register page. If the logon page is used, the register page is never seen. If the register page is used, the logon page is never seen. I don't think that would be a problem, but I may be wrong. Thanks for the reply.

TravMark, here is the code where the Alert is called.

It works here. This is the first page that loads after the Session value is set using this code: Session(&quot;UserID&quot;) = Request.Form(&quot;txtUserName&quot;)

Sub window_onload
Alert (&quot;<%=Session(&quot;UserID&quot;)%>&quot;)
lblDisplayUserName.Caption = &quot;<%=Session(&quot;UserID&quot;)%>&quot;
lblDisplayPassWord.Caption = &quot;<%=Session(&quot;PWord&quot;)%>&quot;
End Sub

But Not here on the next page. This is the second page that is loaded.
Sub window_onload
Alert(&quot;<%=Session(&quot;UserID&quot;)%>&quot;)
txtCltName.focus
End Sub

It's just got me *stumped*
Rob
Just my $.02.
 
is it a huge page? I'd like to see the whole code. the second pair eyes is a great tool.
what happens if you coment out the session.abandon line, (even if it is in an onclick, asp runs all code in <% %> at the server so I think it runs the session.abandon all the time.)
 
Ironically, I was about to post this exact question when I saw this thread.

I am having this problem with only one of my users. On several other computers, I can set the Session variable and it works through all of my pages. However, one user reports that the Session variable is only working on the page immediately following its assignment. The variable does not work on pages past that.

I am inclined to believe that it may be an IE version problem. I don't know which version my user is on but that seems to be the only variable between different users.

I do not have a session.abandon code anywhere in my coding so I know that is not the problem.

Thanks for any help.

Rob (ironic isn't it?)
 
Yea, it is ironic AlaskanDad. If you stumble across something, please let me know here. I'll do the same.

travmak, the code on some of the pages is a little long to post here, but here is the essential code. (I think)

This page submits the info:
<FORM Name=frmReturn Method=post Action=&quot;VerifyClient.asp&quot;>

This is the VerifyClient.asp code:
<%@ Language=VBScript%>
<%Option Explicit%>

<%

Dim cn, rs, cnString, UserName, PWord, sql
Session(&quot;UserID&quot;) = Request.Form(&quot;txtUserName&quot;)
Set cn = Server.CreateObject(&quot;ADODB.Connection&quot;)
Set rs = Server.CreateObject(&quot;ADODB.recordset&quot;)
cnString = &quot;Driver=SQL Server;uid=;pwd=;Server=server;Database=CltInfo&quot;
UserName = Session(&quot;UserID&quot;)
PWord = Request.Form(&quot;txtPWord&quot;)
sql = &quot;Select * from Clients Where UserID = '&quot; & UserName & &quot;'&quot; & &quot;And Password = '&quot; & PWord & &quot;'&quot;
rs.Open sql, cnString
If rs.BOF = True and rs.EOF = True Then
Response.Redirect &quot;IncorrectLogin.asp&quot;
Else
Response.Redirect &quot;ControlPanel.asp&quot;
End If

%>

This is how I have it in the next page (controlpanel.asp)that loads:
Sub window_onload
Alert(<%=session(&quot;UserID&quot;)%>)
End Sub
The controlpanel.asp page alert displays the correct UserID.

This is the page after the ControlPanel.asp loads:(clientUpdate.asp)
Sub window_onload
alert(<%=session(&quot;UserID&quot;)%>)
txtCltName.focus
End Sub
The alert here comes up blank.

The clientupdate.asp page loads on a button click event from the controlpanel.asp. Here is the code for it:
Sub cmdEdit_Click
location.href = &quot;ClientUpdate.asp&quot;
End Sub

If you need more info, I'll try to post it but I think that is the main working part in question here.

I'll be out of town until Monday, but if I get even close to a computer, I'll check back here.

Thanks again Rob
Just my $.02.
 
AlaskanDad,
I got carried away above, sorry. I'm using IE 6.0 and have cookies enabled. I read on MSDN that cookies have to be enabled for the session object to work. As far as the problem I'm having with it holding the session variable, I can't find a thing about it on MSDN. I've looked several hours. You may want to see if that one machine has cookies enabled though. As far as all I've read on MSDN, as long as it is over IE 4.0 it sould work.

travmak,
I did comment out the line I had Session.Abandon in. Same result, blank alert box. Rob
Just my $.02.
 
Yea, I'll post them tomorrow. I'm not at &quot;my&quot; computer now, I'm at a friends house. When I get home I'll post it. Actually though, that is all of the asp code above in the verifyclient.asp. The rest of it is client side vbscript on the other 2 pages. I'll still post it when I get back home.

Thanks Rob
Just my $.02.
 
This is the first page (Return.asp). It gets the logon information (UserID, Password):

<%Option Explicit%>
<%
<!--#Include File=&quot;VerifyClient.asp&quot;-->
%>
<HTML>
<HEAD>
<META name=VI60_defaultClientScript content=VBScript>
<TITLE>MISTEP™ Return</TITLE>
<SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript>
<!--
Sub cmdCancel_Click
location.href = &quot;Index.htm&quot;
End Sub

Sub window_onload
txtUserName.focus
End Sub
-->
</SCRIPT>
</HEAD>
<BODY text=silver vLink=black aLink=red link=gray bgColor=navy>

<FORM Name=frmReturn Method=post Action=&quot;VerifyClient.asp&quot;>
</FORM>
</BODY>
</HTML>

The second page, in the other post, (Verifyclient.asp) is complete there. It is supposed to be used as an Include file but I don't think it is being used that way. It still verifys the data though.

The third page: (ClientUpdate.asp) is made to update the Client's Information.

<%@ Language=VBScript%>

<HTML>
<HEAD>
<META name=VI60_defaultClientScript content=VBScript>
<META name=VI60_DTCScriptingPlatform content=&quot;Server (ASP)&quot;>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
<TITLE>ClientUpdate</TITLE>
<SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript>
<!--

Sub window_onload
Alert(&quot;<%=Session(&quot;TEST&quot;)%>&quot;)
txtCltName.focus
End Sub

Sub cmdCancel_Click
location.href &quot;controlpanel.asp&quot;
End Sub

-->
</SCRIPT>
</HEAD>
</BODY>
</HTML>

I cut all of the HTML out. It was excessivly long.

TIA
Rob
Just my $.02.
 
Sounds like I problem I'm having. Try this

<html><head><title>test cookies</title></head>
<body>
<%
If Request.Cookies(&quot;lastTime&quot;) = &quot;&quot; Then
Response.Cookies(&quot;lastTime&quot;) = &quot;i set this cookie last time<br>&quot;
Response.write (&quot;cookie <b>lastTime</b> was not found<br>&quot;)
Else
Response.Write (Request.Cookies(&quot;lastTime&quot;))
End If
%>

<p><input type=button value=&quot;Show Cookies&quot; onclick=&quot;alert('->' + document.cookie + '<-')&quot;>
</body>
</html>

The first time you go to the page you should get &quot;cookie lastTime was not found&quot;. If you hit refresh you should get &quot;i set this cookie last time&quot;.

For me this works as expected on my intranet running IIS5.0 and MSIE 5.5. Problem is when I try it with MSIE 6.0 it does not work. The cookie is never set! If this doesn't work then sessions won't to work!
 
Yeee Haaa. I found my problem. From
&quot;After you apply this update, Active Server Pages (ASP) cookies are blocked if the server name contains non-DNS supported characters. For example, you cannot use any underscore characters (&quot;_&quot;) in the server name.&quot;

Our dev server is called svr_web1
 
i have a session variable where i store the day of the month clicked in the yearly calendar and show the reports according to the date seleceted by the user
Session(&quot;selectedday&quot;) = myday where myday is a varaible
my problem is i am using this variable as a part of my path in the link like

this variable passes on to the page the first time but say i select another day from the calendar within the next minute this variable does not pass.But if i close the browser and wait for sometime and open a fresh one this works fine.
But the similar code for showing data on weekly basis works fine no matter how many times i go back and select the week number it takes the latest week number as the varaible
can somebody help me on this as i am very new to this field
 
domMod, thanks for posting the link. I'll have a look at it. Rob
Just my $.02.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top