minakshi
minakshi

Reputation: 315

Difference between viewstate and controlstate

What is the difference between ViewState and ControlState in terms of IsPostBack and how they work?

What is the actual use of ControlState?

Upvotes: 13

Views: 12174

Answers (4)

Salim Latif Waigaonkar
Salim Latif Waigaonkar

Reputation: 462

Control state, introduced in ASP.NET version 2.0, is similar to view state but functionally independent of view state. A page developer can disable view state for the page or for an individual control for performance. However, control state cannot be disabled. Control state is designed for storing a control's essential data (such as a pager control's page number) that must be available on postback to enable the control to function even when view state has been disabled. By default, the ASP.NET page framework stores control state in the page in the same hidden element in which it stores view state. Even if view state is disabled, or when state is managed using Session, control state travels to the client and back to the server in the page. On postback, ASP.NET deserializes the contents of the hidden element and loads control state into each control that is registered for control state.

Upvotes: 0

Blue Clouds
Blue Clouds

Reputation: 8161

Since Control State and View State are the same then first question is , isn't it duplication of data? Then we realise there is an advantage to Control State that it cannot be disabled. Then we might think why can't we do the same to View State :) why invent a new "Control State" for that. Now we have duplication of data. The reason to disable View State is nullified by the presence of Control state, right?

That is where the real advantage of Control State comes in. Control State is versatile. That is, a custom control can decide what to store in a control state. Where as view state is not intended to be stored specifically by a control, it is a general out of the box feature available. Because control state has a specific reason(and it has to be dependable) it is not designed to be disabled.

Upvotes: 1

fady massoud
fady massoud

Reputation: 11

The ViewState & ControlState both stores the control properties ,you can disable the ViewState Property only and that will not affect the ControlState at all which loads in the page first loading or if the page is postBack the controlState already loads from saved memory

Upvotes: 1

Parv Sharma
Parv Sharma

Reputation: 12705

Control state is a new construct within ASP.NET 2.0, and it is really nothing more than view state; however, it is view state with a significant advantage; that advantage is that other developers using your control cannot disable control state as they can view state.

http://www.codeproject.com/Articles/15300/Using-Control-State-in-ASP-NET-2-0

Upvotes: 7

Related Questions