Persisting an object across multiple postbacks
Posted on 2005-05-15
I'm contructing a Class within my page who members will be built up across multiple postbacks. My first postback returns a dataset that will be used in all subsquent postbacks.
Performance issues of Session vars aside, I will want to save my object to a session var prior to each postback and re-serialize it on return, won't I? When I try to implement as below I get a Session State error immediately on page entry. But other pages have been using session without problems. I understand that the code is trying to access the session state prior to it's availabilty which makes me question my whole approach.
I've used the MyClass stratagy on a number of other pages and am somewhat comfortable with it but this page is made more complex due to the multiple postbacks. I'm trying to resist the urge to just dump individual values out to session vars but ...[gasp & gag].
Exception Details: System.Web.HttpException: Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive
Public Class MyPage
'crux of the problem here.
Public myContent As MyPage.MyClass = Session("MyContent")
'How can i instantiate the object so all methods can access it but still
'persist it across postback?
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If (Not IsPostBack) Then