Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ViewState and user controls 1

Status
Not open for further replies.

Peppi

Programmer
Apr 9, 2001
205
CA
Hi,

If I set a ViewState variable in my hosting page, can that ViewState variable be accessed from the user control that is a part of that page? It seems like it can't but just wanted to doublecheck. If it can't be accessed, I guess a session variable would be the alternative?

Thx.
 
No, the ViewState is not shared.

Assuming you don't need a persistent variable, then I would suggest using the HttpContext.Current.Items collection as an alternative to Session. It works like Session, but the vars only persist during a single request, so it's easier on server resources:

Code:
  HttpContext.Current.Items["MyVar"] = 1;

If you do need it to be persisted over postbacks, then yes, Session is probably your solution.

-paul

penny.gif
penny.gif

The answer to getting answered -- faq855-2992
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top