Get ViewState in a .VB class file

I need to get viewstate but I am not in a code behind file, I am in a separate class file.  Is it possible?  If so, how?
MeghanOBrienAsked:
Who is Participating?
 
MeghanOBrienAuthor Commented:
I apologize, I went a different way and no longer need viewstate.  Didn't get a chance to try out these solutions, I don't know if I can split the points or what?
0
 
Alfred A.Commented:
You can try to inherit the page class in your separate class file.

Public Class Separate
       Inherits System.Web.UI.Page

End Class

You can then access ViewState within your class.

I hope this helps.
0
 
badalpatelCommented:
You can store a viewstate in  your class variable, and then use it when you need.
This example initialize viewstate in constructor:

      public class MyClass
      {
            protected System.Web.UI.StateBag _viewstate;
            public MyClass(System.Web.UI.StateBag viewstate)
            {
                  _viewstate = viewstate;
            }

            public void DoSomething()
            {
                  string s=(string)_viewstate["key"];
            }
      }
0
 
Alfred A.Commented:
You can split the points if you want.  It can be done in here.  It is up to you.  Goodluck with your projects. :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.