Session vs Viewstate in ASP.NET
What is the difference between SessionState and ViewState in ASP.NET?
If you asked this question to me, the main difference is a session known in a every page in all application and viewstate just only in a page. To know more about Understanding ASP.NET View State just read here . In stackoverflow, some people give their answer like this:
Session State contains information that is pertaining to a specific session (by a particular client/browser/machine) with the server. It’s a way to track what the user is doing on the site.. across multiple pages…amid the statelessness of the Web. e.g. the contents of a particular user’s shopping cart is session data. Cookies can be used for session state.
View State on the other hand is information specific to particular web page. It is stored in a hidden field so that it isn’t visible to the user. It is used to maintain the user’s illusion that the page remembers what he did on it the last time – dont give him a clean page every time he posts back. Check this page for more.
Session state is saved on the server, ViewState is saved in the page.
Session state is usually cleared after a period of inactivity from the user (no request happened containing the session id in the request cookies).
The view state is posted on subsequent post back in a hidden field.