Aymen Kareem Aymen Kareem - 19 days ago 5
ASP.NET (C#) Question

Should I use session or viewstate to save values when posting back a form fields?

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?

Answer

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.