ViewState is used to manage asp.net server side controls state accross page postbacks. We can always store our own custom information into the viewstate. While storing custom information note should be made of the size of the viewstate as it impacts the page rendering time at the client end.
Session is used to manage information for a particular user session. Any information that is needed with in a particular user's session can be stored here.
Caching is used in asp.net to store objects in memory that require extensive server resources to create. You can establish an expiration policy with this.
As a general rule of thumb -
- You use ViewState to store small amounts of data that is needed within the same page.
- You use Session to store data that is needed within the same user session.
- You can use data caching to store data that is needed accross user sessions through out the application.
Comments