Viewstate and session state.

Posted on 2007-07-31
Last Modified: 2010-04-15
What is the difference between Viewstate and session state. Which one should I use?

1)Unlike Session state ViewState is a property of the web controls.
2)Values stored in the session are available across different pages in an

Where as the data contained in a control is persisted between page's post back by

using that controls ViewState property.
3)View state cannot be used if the page donot post back to itself and nformation is

stored in client only.
4)Moreover Viewstate are not secured as data is exposed to client. although  we  can

configure page directive and machine key to make view state encrypted. Where in case

of session this is user specific data that is stored in server memory . Session

state is valid for any type of objects.
Question by:mathieu_cupryk
    LVL 29

    Expert Comment

    by:Gautham Janardhan
    these are completely different stuff what exactly are u looking for
    LVL 29

    Expert Comment

    by:Gautham Janardhan
    view state doesnt require any server resources for its operation. It is passed to the client during every postback as an hidden element. Since it is added with every page, it adds few Kbytes to the page. This effects the loading of the page in the client. Other main problem with Viewstate is, since it is passed as plain text to the client. Anybody can tamper this value, because of this you shouldnt store any important data in the viewstate
    LVL 29

    Accepted Solution

    there are four states in asp

    Application State

    Global to the application

    shared across all clients
    Overuse limits scalability
    Not shared across multiple machines in a Web farm or processors in a Web garden
    Primary purpose subsumed by data cache in ASP.NET

    Session State

    Per client

    Can configure to be shared across machines in a Web farm and processors in a Web Garden


    Requires cookies or URL managing to mange client association
    Off-host storage can be inefficient

    Cookie State

    Per client


    Works regardless of server configuration
    State stored on client
    State can live beyoond current session


    Limited memory (-4KB)
    Clients may not support cookies or may explicitly disable them
    Stae is sent back and forth with each request

    View State

    Across POST request to the same page


    Works regardless of server configuration

    State is retained only with POST request made to the same page
    State is sent back and forth with each request

    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

    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    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…

    730 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

    16 Experts available now in Live!

    Get 1:1 Help Now