Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would you ever use asp.net's ViewState storage object over the Session storage object?

Other than because session storage is session-global to more than one page, why would you ever want to use the viewstate to hold values?

It seems kind of ridiculous to send any kind of information other than a few small query string like values, back and forth from the client to server. I mean what a waste of bandwidth(!), simply for storage purposes. The session, while global across multiple pages, seems like a completely superior alternative to the viewstate.

Especially with asp.net ajax controls and variants, the viewstate could quickly become bloated tracking the various states and variables of all those different controls and html elements.

But then why is there viewstate storage for page variables and objects at all?

Maybe I'm missing another great usage for the page's viewstate storage, does anyone know something out there?

Thanks for reading!

EDIT: Everyone had a great answer, sorry if I didn't pick yours.

like image 782
Mark Rogers Avatar asked Feb 22 '09 19:02

Mark Rogers


1 Answers

Sessions run out, Viewstate does not - you can go back an hour later and your viewstate will still be available. Viewstate is also consistently available when you go back/forward on the website, Session changes.

like image 151
Mark S. Rasmussen Avatar answered Oct 25 '22 14:10

Mark S. Rasmussen