0

What's the best way (if there is a way) to define a variable for use by controls on one page, but should be disposed of after navigating away from that page? Is there anything like HttpContext.Current.Items that only persists per page?

4
  • 1
    Can you just define a variable on the class that inherits from Page itself? You can retrieve the Page on which the controls exist from within the control itself (user or otherwise) via the Page property, cast it to the sub-class type, and access the variable. You could also subclass UserControl if it's just the user controls that are going to need it. Commented Mar 26, 2012 at 17:57
  • That sounds good, I'll try that if there's no 'easy' way to do it, thanks Commented Mar 26, 2012 at 17:59
  • It is possible; I didn't mean to ask whether it was -- I was suggesting it as a solution. Commented Mar 26, 2012 at 18:00
  • Ah, just seen in Intellisense that there is already a Page.Items - so I'll give that a go Commented Mar 26, 2012 at 18:11

1 Answer 1

2

There's a thing called Viewstate http://msdn.microsoft.com/en-us/library/ms972976.aspx

that may provide the functionality you want. If not, try to be more specific on how do you want to use those variables.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.