Differences in AJAX Control Toolkit Controls and Extenders Client State
Sorry for the long title, but I wanted to post about some of the differences between the controls and extenders client component's client state, which are defined for AjaxControlToolkit.ControlBase and AjaxControlToolkit.BehaviorBase on the client. In developing an AJAX Control Toolkit control, I've come to find some of the differences. One of the key differences is with client state.
Client State is a hidden field mechanism that stores data about the current state of the AJAX control. For an AJAX control toolkit extender that supports client state, on the client the get_ClientState and set_ClientState properties are avaialble to read/write data to this hidden variable. This works really easily on the client, plus it allows the server to access the value through the ClientState property, and load/save the client state value.
For a control, however, a control developer needs to override the SupportsClientState property, and return true. Furthermore, there are no equivalent properties on the client. Instead, the get_clientStateField and set_clientStateField get and set the reference to the field, so it's possible to read and write the values using this reference through get_clientStateField().value. This only works if SupportsClientState is set to true. Controls also have to use the LoadClientState and SaveClientState methods to load/save state. State is loaded whenever LostPostData occurs and saved when the hidden field is registered.
Another interesting variation is that the control base class uses the ScriptManager's RegisterHiddenField, whereas the extender creates its own hidden field reference so that the developer can work directly with the ClientState property.