ASP.NET Ajax Beta: AutoCompleteBehavior without a Web Service
A lifetime ago, and several Microsoft AJAX releases ago, I extended the built-in AutoCompleteBehavior and AutoCompleteExtender, enabling it to gather its list of completion items via a callback to the page rather than a web service. Well it seems like I hit a nerve with it, because it became pretty popular!
The problem is it was written to work with the July CTP of Atlas. But now we're on Beta 2! So, by popular demand, it is time to give the old thing an overdue face lift.
Like before, this version of the AutoComplete extender has the following advantages over the built in one:
- Optionally uses an ASP.NET callback to query for completion items.
- In callback mode you can keep the completion query logic encapsulated within the page, allowing you to access the page state.
- The Extender raises an event when completion items are requested, making providing completion items as easy as handling a button click.
- Inherits from the base extender, so you can swap it out easily!
Unlike my original version, I did not create a derived TextBox class this time. The new model for how extenders attach makes it somewhat less necessary to go that far.
I will post an example application using this extender shortly.
Use the source however you like... change it, trash it, claim it as your own, I don't mind :) This is just meant to be an example of extending from a base AJAX component yet still doing something more useful than Hello World. Enjoy!
Update 2/19/07: You can also download Leo Vildosola's sample VS2005 Web Application project here.
To use it, you will need both the Beta 2 install of AJAX extentions, and the Futures preview CTP. Then either add the linked project to your solution and reference it, or build it then reference the DLL directly. Add a tag prefix to your page:
<%@ Register TagPrefix="i88" Namespace="Infinity.Web.UI.WebControls" Assembly="Infinity.Web" %>
And use it! Here it is with callback mode enabled:
<i88:SmartAutoCompleteExtender id="auto1" runat="server" TargetControlID="Textbox1" UpdateMode="Callback" OnAutoCompleteCallback="[my event handler]" />