Auto-complete using ATLAS

Setting up an auto-complete input box in ATLAS is pretty simple, here is a quick guide to illustrate this...

Assuming you already have the ATLAS framework referenced in your project then select an <asp:TextBox> to apply auto-complete to.

See Mark's article for adding ATLAS to an existing web site: http://www.geekzilla.co.uk/View2C00AD81-BA3C-4E02-A265-C2C3925B4B23.htm

Start by adding the following auto-complete extender, referencing the TextBox object you want to extend...

<atlas:AutoCompleteExtender runat="server" ID="Extender1" DropDownPanelID="drop" >
  <atlas:AutoCompleteProperties Enabled="true" TargetControlID="myTextBox" 
  ServiceMethod="myWebMethod" ServicePath="myWebService.asmx" />
</atlas:AutoCompleteExtender>

Note the ServiceMethod and ServicePath attributes, these specify the webservice and method that will take what the user has typed so far and return an appropriate list to select from.

The web method definition should be as follows:

[WebMethod]
public string[] myWebMethod(string prefixText, int count)
{
    string[] vals;
    //populate vals
    return vals;
}

The user input so far is passed into prefixText and maximum number of records to return is passed into count (although this is a 'recommendation' only - the control will show whatever count you return).

The string[] returned will be displayed in the familiar auto-complete dropdown panel allowing the user to select a valid response either with the mouse or cursor keys.

By default the auto-complete does not kick in until the user types a third character in the TextBox - this default can be overridden using the MinimumPrefixLength attribute. Consider that the webmethod will be called for every keystroke after this minimum so do ensure that the webmethod will return in a timely manner or a few users typing will generate significant load on your server.

If your method is by necessity slow, then consider increasing the minimum prefix.

Similar to with making web service calls from javascript (see http://www.geekzilla.co.uk/View91E6FCCB-DB0A-499C-A2CC-9854452D2086.htm) there seems to be a limitation in that the web service must be part of the same project.

Author Dave Howard

I have been involved in IT development for the last 10 years - a lot of it around desktop applications and telecoms.

Comments

miner said:

Hi Dave,

I was wondering if you could help me get the autocompleteextender to work on a textbox in a detailsview control. I am using the unique ID for the textbox (truncated, e.g. dvSpecies$tbSpecies). I don't get any errors but I also don't get the autocomplete results. Any suggestions would be greatly appreciated.

PS I have searched all over the web and cannot find anything relavent.

03/Sep/2006 17:46 PM

Lucas Stark said:

Your Web service does not need to be in the same project, just in the same domain as the caller script.

20/Feb/2007 16:41 PM

Add Comment

Name
Comment
 

Your comment has been received and will be shown once it passes moderation.