ASP.NET session Variables

G

Guest

I save a session variable on page 1 and link to page 2. When page 2 loads,
the session variable is null. Can anyone help?

I'm using Visual Studio 2003 (VB)

Session settings in web.config

<sessionState
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
cookieless="false"
timeout="20"
/>

Code on Page 1
Dim sesvar As String

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
sesvar = "Blank Statement"
Me.ShowSessionVar.Text = sesvar
End Sub

Private Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles SaveButton.Click
sesvar = "New Session Variable at " + Format(Now(), "dd/mm/yyyy
hh:mm:ss")
Me.ShowSessionVar.Text = sesvar
Session("SesMessage") = sesvar.ToString
End Sub


code on page 2
Dim P2sesvar As String

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Session("SesMessage") Is Nothing Then
P2sesvar = "Session Variable is Null"
Else
P2sesvar = Session("SesMessage")
End If
Me.P2SessionVar.Text = P2sesvar
End Sub
 
H

Hammad Rajjoub

Hello,

I am not sure why arent you able to retrieve your sessions once have
added it. And i am sorry that i m too busy and cant add your code to
asp.net solution and try it my self. However I would like to suggest
you a following link at msdn that talks about ASP.NET state management
with Sessions:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconsessionstate.asp

You should be able to retrieve your session variables once you have
added them, unless and untill they time out or have been cleared
explicitly.

best regards,
Hammad Rajjoub
MVP (XML Web Services)
http://dotnetwizards.blogspot.com
 

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

Top