≡ Menu

Session vs ViewState

Session State is useful for storing values that must be persisted across
multiple pages by the same user. ViewState is useful for storing
serializable data that must be persisisted across PostBacks by a single
page. If you use Session State, the value you insert will remain in memory
until (1) The Session times out, or (2) Your code removes it. If you use
ViewState, the value you insert will remain in ViewState until the user
requests a different page.

ViewState stores data betwen PostBacks by putting it into a hidden form
field on the client HTML doc. when the doc is Posted Back, the values are
read from the hidden form field and stored in memory until the page has
finished processing. If ViewState is particularly large (and I’m talking KBs
here, not 6 bytes), it can negatively affect the speed at which the HTML doc
is downloaded by the browser.

Use the right tool for your job. I think after my explanation, it should be
obvious that you would want to use ViewState in your specific case.

{ 0 comments… add one }

Leave a Comment