Difference between SessionState and ViewState in asp.net
- If you want to store infromation that you want to access on different pages then you can use SessionState.
- SessionState is saved on the server.
- Data stored in the SesionState will be cleared when the session expired(usually after 20min of inactivity when using session inproc).
- SesionState is used to save the user specific data like UserID, User Role, etc.
- If you want to store information that you want to access only with in the page(same page) then you can use ViewState.
- ViewState is saved in the page.
- Data stored in the ViewState will send back to the server when postback action performed (no expiration).
- ViewState is used primarily by Server controls to retain state only on pages that post data back to themselves. And when you want to save the pagelevel data you can use ViewState.
Useful ToolsOnline Code Editor and Compiler HTML Minifier Online HTML Compiler/Preivew Word Count Tool Replace Text/Word tool