Link to home
Start Free TrialLog in
Avatar of MeghanOBrien
MeghanOBrienFlag for United States of America

asked on

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?
Avatar of Alfred A.
Alfred A.
Flag of Australia image

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.
Avatar of badalpatel
badalpatel

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"];
            }
      }
ASKER CERTIFIED SOLUTION
Avatar of MeghanOBrien
MeghanOBrien
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can split the points if you want.  It can be done in here.  It is up to you.  Goodluck with your projects. :-)