Aymen Kareem Aymen Kareem - 1 year ago 73
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 Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download