I am still a beginner and I can't figure out the difference between Session and ViewState.
For example, when posting back a page, which one should we use to store our variables, Session or ViewState? Why?
I am still a beginner and I can't figure out the difference between Session and ViewState.
For example, when posting back a page, which one should we use to store our variables, Session or ViewState? Why?
1) Session and viewstate are very opposite based on its stored value..
Session stores value at the server side and viewState stores value at clientside in page as a
hidden field (you can see by view pagesource option).
2) Viewstate can not navigate stored value by it's post backing page(or redirecting page), but session can share values between all the pages in the application scope.
Depend on your requirement to access those values on postback, you can store variable either in session or in viewstate. If you do not want to access value of variable in other pages, then you can use viewstate, else session.