Storing small amount of data in ViewState

Hello, I have a number which is incremented, which needs to be saved and retrieved at various times on postback. Which of the three would be the best method to store the  number/integer.

1. View State
2. A hidden variable on the page.
3. Session variable.

Or can someone rank the above above methods, in regards to which method is best.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
"Best" is a subjective term. What does "best" mean to you?
brgdotnetcontractorAuthor Commented:
Secure, Reliable etc...etc..
Manoj PatilSr. Software EngineerCommented:
Since the Session Variables are stored on Server side , you can store and retrieve the data easily.
The benefit of this is, you can use session on other pages too, if you want.
Just with the 2 lines of code.

To Store in Session Variable :
int number=10;

To retrieve from Session Variable :

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
brgdotnetcontractorAuthor Commented:
Hi, I like Session, but sometimes the data will expire. What is your opinion of using ViewState instead?
Manoj PatilSr. Software EngineerCommented:
You can use ViewState but if you want the value on other page, the easiest way is Session.
For session
you can increase the Timeout of Session in your configuration. So that's not the problem.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

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.