ViewState vs Session State

Whether to use ViewState or Session State in an ASP.NET App depends on the individual use case and it is likely that you will use both for different scenarios in your web application.

For data that needs to persist for a user’s entire session across multiple pages you should use Session State since ViewState is only applicable to a single page and is lost when the use navigates away from a page.
However Session State data is stored in-memory and can have a performance penalty if large amounts of user data are stored. For data which is only required on a single page – for example data on a user’s preferences for that page’s controls it can be more efficient to store that in the ViewState. Note that ViewState is posted to the server and then returned from the server on each postback and so there can be a performance penalty, especially when using AJAX.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>