Converting a session object

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I convert a session object to a user object

Dim _Customer as Customer
_Customer = Session("Customer")

How do I convert the Session object to the user object in vb syntax?
 
Dim _Customer as Customer
Session("Customer") = _Customer

Whenever you save an object to Session state, it is implicitly cast as
System.Object.

In order to get it back, you just explicitly cast it back to your object
type.

_Customer = CType(Session("Customer"), Customer)


Here is an article that may help:

http://www.codeproject.com/dotnet/CheatSheetCastingNET.asp

This article touches on 'Option Strict' which you can set to force VB to be
strictly-typed. It is good to get in the habit of turning Option Strict ON
(not the default for VB).

Good luck!
 
Back
Top