944,114 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 13679
  • ASP.NET RSS
Dec 7th, 2005
0

Differences between Session and ViewStates?

Expand Post »
Hi All,
I would like to know the differences between Sessions and Viewstates. And best uses of Sessions and Viewstates.

Thanks and with regards,
Madhusudhan
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cumadhu is offline Offline
19 posts
since Sep 2005
Dec 7th, 2005
0

Re: Differences between Session and ViewStates?

"Session" is data stored per user session. "Viewstate" is an ASP.NET thing. It's a way for the application to maintain state about a particular form and its child controls. Your ASP.NET application might consist of several pages/forms. There might be a piece of data that you want to access across all pages. You could place that in a Session variable. However, you rarely need to worry about ViewState, ASP.NET manages that itself.

I've written some articles that discuss Viewstate: http://www.tgreer.com/aspnet_html_02.html

This article shows how you might use Session: http://www.tgreer.com/aspnet_html_04.html
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
Feb 5th, 2010
0
Re: Differences between Session and ViewStates?
Both Session and ViewState are a way of storing data. The following are the differences.
.1) Session is for per user session. ViewState is for a page. ie. Storing data in a session variable will last till the session ends. Whereas storing data in ViewState will last only till the page is in live.
2) Session is server type storage where as ViewState is client side type storage.
3) Session variables are stored in a SessionStateItemCollection object that is exposed through the HttpContext.Session property. ViewState variables are stored in hidden fields.
4) When using a SessionState Mode other than Inproc, the session variable type must be either a primitive type or serializable. This is because the session-variable is stored in an external data store. There is no mode for ViewState. By default, serialization of data will be taken care by the viewstate.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
meeram395 is offline Offline
1 posts
since Feb 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: print report
Next Thread in ASP.NET Forum Timeline: Accessing Datagrid selected row cell value (c# .NET)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC