Introduction

In this tutorial we're going to examine the principals and construction of a basic ASP.NET 3.5 AJAX extender control. We'll discover how powerful extender controls can be for the reusability of code and behaviors. For more information on extenders refer to my books ASP.NET 3.5 AJAX Pocket Guide and ASP.NET AJAX Programming Tricks.

As we know, ASP.NET comes packed with a vast number of different controls, all having their own particular uses. However, it may become desirable to extend the behavior of these controls to better suit our needs. In most cases, the extension of these controls would involve building a new custom control, which inherits from the control we wish to extend and the new features coded. For example, consider a TextBox control, you may wish to limit the input of this control, change the background color when focus of the control has been changed, or display a watermark within the content of the control, etc. Building individual controls implementing each of the discussed behaviors, while definitely an option, is perhaps not the best option. What you’ll end up with is several different controls, all of which actually TextBox controls, however, each implementing a slightly different behavior, aside from being a tedious and repetitive task, it’s not the most efficient approach.

Welcome to concept of an extender control. Extender controls represent logical behaviors that can be attached to an existing control. Extender controls are server controls and can be attached to another control simply by identifying the client ID of the control we wish to extend.

Extender controls are standalone server controls, they implement from the Control class, have a Render() method and functions in a manner expected from any other server control. However, extenders offer the ability of injecting client-side code into the pages markup, hence granting the ability of extending the physical behavior of a server control. The controls an extender extends are not changed programmatically and are simply extended via client-side code, for example the addition of JavaScript event handlers to perform specific tasks based on a particular trigger. Extenders are specific to the ASP.NET AJAX Framework, this Framework simplifies the development of extender controls, as it offers a detailed client-side library we may make use of and also offers base classes we should inherit from when developing extender controls.

Extenders usually include a number of client-side objects defining the behavior of the target control. These objects are then written to the output stream by registering themselves with the ScriptManager control included within the page. A ScriptManager control must be present when making use of the ASP.NET AJAX base extender class.

Download all source files

Read more...