70-564 - Control Extenders + Control Adapters

Filed under: , , , by:

My two previous posts described how to extend a basic behavior of controls without changing them. Ajax control extenders add Ajax/JavaScript behavior to controls and control adapters can provide different rendering for controls without changing them. One of the disadvantages of control extenders is that they can extend only 1 control, so there is 10 controls to extend, 10 extenders must be added to a page. And if we want to add an extender to each control (we want to extend) in the whole ASP.NET application, we would have to go through all pages and add a lot of code. That would be definitely tedious and could take a lot of time if an application has many pages. But that's where control adapters come in handy. We would need to create an adapter for the control being extended and override CreateChildControls method to generate ControlExtender markup and add it to as a child the control. Make sure that if the adapter overrides the Render and RenderChildren method, it calls the RenderChildren method from an override of the Render method. Of course it is not very common to add extenders to every single control type within a Web application (especially because Ajax Control Extenders require Ajax ScriptManager on a page so we would need to make sure that one is present on the page that contains a control to which an extender will be added), but there might be situations that it would be desirable. For developers who are not aware of this solution that would mean a lot of tedious work so most probable that task would either not be accomplished as someone would decide that it wouldn't be worth so much resources (time and money) or would take a lot of time (and money). In situations like that you can really see the difference between a developer for whom developing is a mere means of earning money and a thriving developer for whom it is also a hobby and excitement.

0 comments: