Storing small amount of data in ViewState

Posted on 2014-07-13
Last Modified: 2014-07-20
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.
Question by:brgdotnet
    LVL 74

    Expert Comment

    by:käµfm³d 👽
    "Best" is a subjective term. What does "best" mean to you?
    LVL 2

    Author Comment

    Secure, Reliable etc...etc..
    LVL 19

    Accepted Solution

    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 :
    LVL 2

    Author Comment

    Hi, I like Session, but sometimes the data will expire. What is your opinion of using ViewState instead?
    LVL 19

    Assisted Solution

    by:Manoj Patil
    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.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now