mfancher
April 3rd, 2004, 05:48 PM
What causes Session state variable to not be saved?
I have the following code:
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 Not IsPostBack Then
'Create a new FlashCard object
FlashCard = New FlashCardClass
'store the object in a Session variable.
Session("FlashCard") = FlashCard
Else
'Get the Session FlashCard object
FlashCard = Session("FlashCard")
End If
RefreshDisplay()
End Sub
The first time through, it runs through If Not IsPostBack and I see the Session("FlashCard") is set.
When I enter text into a text box on the Web Form it displays, which returns me to this code, it runs through the Else, and does not have a value in the
Session("FlashCard")
Aslo, the Session.IsNewSession is = TRUE.
So when I try to use the FlashCard later, it give me the following error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 55: End Sub
Line 56: Private Sub RefreshDisplay()
Line 57: lblFirst.Text = FlashCard.FirstNumber
Line 58: lblSecond.Text = FlashCard.Operation & FlashCard.SecondNumber
Line 59: End Sub
Does anyone have any idea what's going on here? Any help would be greatly appreciated!
Thanks,
Melena
I have the following code:
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 Not IsPostBack Then
'Create a new FlashCard object
FlashCard = New FlashCardClass
'store the object in a Session variable.
Session("FlashCard") = FlashCard
Else
'Get the Session FlashCard object
FlashCard = Session("FlashCard")
End If
RefreshDisplay()
End Sub
The first time through, it runs through If Not IsPostBack and I see the Session("FlashCard") is set.
When I enter text into a text box on the Web Form it displays, which returns me to this code, it runs through the Else, and does not have a value in the
Session("FlashCard")
Aslo, the Session.IsNewSession is = TRUE.
So when I try to use the FlashCard later, it give me the following error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 55: End Sub
Line 56: Private Sub RefreshDisplay()
Line 57: lblFirst.Text = FlashCard.FirstNumber
Line 58: lblSecond.Text = FlashCard.Operation & FlashCard.SecondNumber
Line 59: End Sub
Does anyone have any idea what's going on here? Any help would be greatly appreciated!
Thanks,
Melena