Problem with Session State

J

John Morgan

I am using asp.net 2.0

I have not used session state for some time possibly just in ASP.net
1.1 and ASP


I have always found it a simple technique but now in ASP.NET 2.0 I am
getting a perplexing problem and I would be most grateful for some
help.

I have an ASPX 2.0 page which has the following code:

****************************

Session("userID") = 22

response.redirect ("walkEntry.aspx")

********************************

The walkEntry,aspx page has the following code:


Sub page_load......

dim intUserID as integer

intUserID = Session("userID")
Response.Write(intUserID)

end sub
**************************************
When the code is run the walkEntry.aspx page shows the intUserID
value as 0

If I then go to the browser window and re-enter the page and press
Enter on the keyboard then walkEntry.aspx shows up properly and the
intUserID value shows up correctly as 22


Where am I going wrong?

Best wishes, John Morgan
 
H

Hal Rosser

intUserID = Session("userID")
Response.Write(intUserID)

end sub
**************************************
When the code is run the walkEntry.aspx page shows the intUserID
value as 0

If I then go to the browser window and re-enter the page and press
Enter on the keyboard then walkEntry.aspx shows up properly and the
intUserID value shows up correctly as 22


Where am I going wrong?

Try casting. If you have Option Strict On.
The Session variable is stored as an object - not as an Integer.
Something like this may work:
intUserID = CInt( Session("UserID") )

HTH
Hal
 
J

John Morgan

Thanks Hal for your suggestion but I still cannot get it to work.

I have looked at a couple of reference books, altered my code and am
still unsuccessful

Option strict is off

I have tried the following on the 'loginuser.aspx' page

txtUserID.Text = CStr(123)

Session.Item("userID") = (txtUserID.Text)

Response.Write(Session.Item("userID"))

That works in that the response write shows
Session.Item("userID") correctly as 123

I then alter the code to

Session.Item("userID") = (txtUserID.Text)
Response.Write(Session.Item("userID"))
Response.Redirect("enterWalk.aspx")


and then try to pick up Session.Item("userID") from the
"enterWalk.aspx" with the following code

Sub page_load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

Dim intUserID As String = CType(Session.Item("userID"), String)
Response.Write("intUserID" & intUserID)

End Sub

The intUserID is not picked up.

Can you or anyone supply code which is guaranteed to work?
I think I am missing something fundamental,

Best wishes, John Morgan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top