ASP.Net AJAX Auto Complete Control Extension

Today while working on adding tagging to items, I came across an issue with the auto complete control extender available in the ASP.Net AJAX Control library.

The problem is that you can’t host the extender in a custom user control (ascx file) and make it call back to a Page Method to retrieve the auto complete list. The reason for this is that the PageMethod() function in the javascript that is used to drive this functionality only hooks into the page itself, not the hosted control.
I’ve got a quick and dirty workaround for this, which works for me in the short term but I’m going to work on refining. It goes a little something like this…

Set up your extender in your user control…


Configure your script manager to allow calls to page methods…


Add the following method to your page. It’s important to make sure the signature matches exactly!


Then simply add the code you need to retrieve your item list to the method body. The hook will now catch the GetCompletionList method as it should and the extender will populate as normal.

Where to next? I’m currently investigating the possibility of using the StackFrame class to branch to different methods based on the caller to this method. There is potential then to have multiple auto complete extenders on the same page across various controls.

If you’ve done something similar – or have a better way to do this, leave a comment and let me know. I’m sure there’s a better way out there… I just haven’t got there yet 🙂

Advertisements

2 thoughts on “ASP.Net AJAX Auto Complete Control Extension

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s