You are on page 1of 2

1.Difference between ViewState and SessionState S.No 1 2 ViewState View state is maintained in page level only.

View state of one page is not visible in another page.i.e., when user requests another page previous page data will be no longer available. View state information stored in client only. View state persist the values of particular page in the client (browser) when post back operation done. View state used to persist pageinstance-specific data. SessionState Session state is maintained in session level. Session state value is available in all pages within a user session.i.e., The data will be no longer available if user close the browser or session timeout occurs. Session state information stored in server. Session state persist the data of particular user in the server. This data available till user close the browser or session time completes. Session state used to persist the userspecific data on the server side.

3 4

2.Difference between ViewState and ControlState

S.No 1 2

ViewState ViewState can be disabled ViewState is implemented by using EnableViewState property of a control to true.

ControlState Control State cannot be disabled. Control State works even when EnableViewState is off. To use Control State (for example in a custom control) we have to override OnInit method,call RegisterRequiresControlState method in OnInit method and then override the SaveControlState and LoadControlState methods. Control State is used for small data only. eg: maintain clicked page number in a GridView even when EnableViewState is off

ViewState is used to maintain page-level state for large data

3.Difference between SessionState and Cookies

S.No 1

SessionState

Cookies

Session can store any type of data Cookies can store only "string" because the value is of datatype of datatype "object" These are stored at Server side Session are secured because it is stored in binary format/encrypted form and it gets decrypted at server Session is independent for every client i.e individual for every client There is no limitation on size or number of sessions to be used in an application For all conditions/situations we can use sessions We cannot disable the sessions.Sessions can be used without cookies also(by disabling cookies) The disadvantage of session is that it is a burden/overhead on server Sessions are called as NonPersistent cookies because its life time can be set manually They are stored at Client side Cookie is non-secure since stored in text format at client side

2 3

Cookies may or may not be individual for every client Due to cookies network traffic will increase.Size of cookie is limited to 40 and number of cookies to be used is restricted to 20. Only in few situations we can use cookies because of no security We can disable cookies

6 7

Since the value is string there is no security We have persistent and non-persistent cookies

Please visit my blog @ http://onlydifferencefaqs.blogspot.in/

You might also like