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!

Session vars in class file

Status
Not open for further replies.

cRaCKh0rN

Programmer
Nov 4, 2005
6
GB
I am trying to create a property in a class like so

Public Shared Property OrderList() As ArrayList
Get
If System.Web.HttpContext.Current.Session("IsOrder") Is Nothing Then
Return System.Web.HttpContext.Current.Session("IsOrder")
End If

End Get
Set(ByVal Value As ArrayList)
System.Web.HttpContext.Current.Session("IsOrder") = Value
End Set
End Property


This always errors with an System.NullReferenceException.

My question is how do i set this session variable to stop it falling over? If i do System.Web.HttpContext.Current.Session("IsOrder") = new ArrayList or System.Web.HttpContext.Current.Session("IsOrder") = "test" it still errors and says the object does not exist!

I have tried other ways including trying to set the value in the new() but these fail. Am i missing something really obvious about setting session variables in a class?

Please help!

 
I'd expect it to return a Null error as your Get method tries to return the value if the session item "Is Nothing". Use "IsNot Nothing" instead...


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Hi, i have tried it various ways. Please also note this other post i have found here. This person has the exact problem


Even i remove the checking and try to do for example
System.Web.HttpContext.Current.Session("IsOrder") = myArray it will fall over in the same way.

Thanks
 
Ok, i have worked out some of my problem to an extent.

I was making an instance of the class before page load as i wanted it available globally to the page.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top