Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 377
  • Last Modified:

Viewstate and session state.

What is the difference between Viewstate and session state. Which one should I use?

1)Unlike Session state ViewState is a property of the web controls.
2)Values stored in the session are available across different pages in an

Where as the data contained in a control is persisted between page's post back by

using that controls ViewState property.
3)View state cannot be used if the page donot post back to itself and nformation is

stored in client only.
4)Moreover Viewstate are not secured as data is exposed to client. although  we  can

configure page directive and machine key to make view state encrypted. Where in case

of session this is user specific data that is stored in server memory . Session

state is valid for any type of objects.
  • 3
1 Solution
Gautham JanardhanCommented:
these are completely different stuff what exactly are u looking for
Gautham JanardhanCommented:
view state doesnt require any server resources for its operation. It is passed to the client during every postback as an hidden element. Since it is added with every page, it adds few Kbytes to the page. This effects the loading of the page in the client. Other main problem with Viewstate is, since it is passed as plain text to the client. Anybody can tamper this value, because of this you shouldnt store any important data in the viewstate
Gautham JanardhanCommented:
there are four states in asp

Application State

Global to the application

shared across all clients
Overuse limits scalability
Not shared across multiple machines in a Web farm or processors in a Web garden
Primary purpose subsumed by data cache in ASP.NET

Session State

Per client

Can configure to be shared across machines in a Web farm and processors in a Web Garden


Requires cookies or URL managing to mange client association
Off-host storage can be inefficient

Cookie State

Per client


Works regardless of server configuration
State stored on client
State can live beyoond current session


Limited memory (-4KB)
Clients may not support cookies or may explicitly disable them
Stae is sent back and forth with each request

View State

Across POST request to the same page


Works regardless of server configuration

State is retained only with POST request made to the same page
State is sent back and forth with each request

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now