Friday, May 3, 2013

Difference between ViewState and ControlState?

ViewState and ControlState are both mechanisms used in ASP.NET for maintaining data across postbacks. Both are preserved in a hidden field known as _VIEWSTATE.
The differences are:
1)ViewState can be disabled while the Control State cannot be disabled.
2)ViewState is implemented by using EnableViewState property of a control to true.
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.

Custom Controls code is written in classes derived from WebControl.

3)Control State is used for small data only.
eg: maintain clicked page number in a GridView even when EnableViewState is off

1 comment:

  1. how to find duplicate record according to multiple column

    select * from (select COUNT(*) c ,PID from test group by PID, position) T where t.c >1

    ReplyDelete