Avatar of dwoolley3
dwoolley3
Flag for United States of America asked on

How can I access ViewState in a class other than a code-behind file?

For both Session State and Application State, we can access the values stored there from a class other than a code-behind file by using the Current property of the HttpContext class. For example:
•      HttpContext.Current.Application["HitCount"];
•      HttpContext.Current.Session["Email"].ToString();
If we were in the code-behind file, we could access these by simply using
•      Application["HitCount"]
•      Session["Email"].ToString()
For View State, how can we access values stored in View State when we are in a class other than a code-behind file?

I experimented a bit, and verified a method in a class located in the App_Code folder would not recognize Session or Application unless I preceded it with HttpContext.Current. Further, it did not recognize ViewState at all. Further, I found that "static" methods in any class (including the code-behind) would fit this scenario where the HttpConext.Current would need to precede the Session and Application in order to be recognized, and the ViewState is not recognized at all (at least not by the Intellisence of Visual Studio 2008). How can I get ViewState from the page to be recognized in these methods/classes?
ASP.NETC#.NET Programming

Avatar of undefined
Last Comment
quizwedge

8/22/2022 - Mon
SOLUTION
kaufmed

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
amit_g

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
quizwedge

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy