Related link: http://www.hauser-wenz.de/s9y/index.php?/archives/153-The-Atlas-AutoCompleteExte…

One of the most anticipated new features of the Atlas December CTP is the AutoCompleteExtender which adds a feature like Google Suggests to a web page. Nikhil Kothari blogged about the new release, but I did not find a complete step-by-step example (although I honestly did not look very long for it). So I sat down and played around with it and found out how this feature works.
The first step is quite easy: Take the <atlas:AutoCompleteExtender> control and put it in your code. Link it to an existing web control you would like to “auto-complete”, ideally a textbox control. Then, link these two controls using the TargetControlID attribute and provide the URL to a web service and the name of a web method within it:

<asp:TextBox ID="vendor" runat="server"></asp:TextBox>
<input type="button" value="Search" />

<atlas:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server">
  <atlas:AutoCompleteProperties Enabled="true" ServicePath="AutoCompleteSample.asmx"
    ServiceMethod="GetValues" TargetControlID="vendor" />
</atlas:AutoCompleteExtender>

On the server side, you have to write this web method. The only difficulty is to find out the method signature. Well, here it is:

public string[] MethodName(string PrefixText, int count) {}

Obviously, PrefixText is the string to search for, and count the maximum number of matches to be returned and displayed. It is also important to know that only .NET Web Sevices are supported

This being said, it is very easy to write a little lookup code. You could query a database, or you just use a static dictionary as in the example below. I know that there are numerous possibilities to optimize the code, but hey, it works :-)

<%@ WebService Language="C#" Class="AutoCompleteSampleService" %>

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = "http://hauser-wenz.de/")]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class AutoCompleteSampleService : System.Web.Services.WebService
{

  [WebMethod]
  public string[] GetValues(string PrefixText, int count)
  {
    string[] values = { "incomplete", "inconsistent", "incompatible", "impossible", "important", "increment", "include", "impose" };
    int matches = 0;

    for (int i = 0; i < values.Length; i++)
    {
      if (values[i].StartsWith(PrefixText))
      {
        matches++;
      }
    }

    int size = Math.Min(matches, count);
    string[] output = new string[size];
    for (int i = 0; i < values.Length; i++)
    {
      if (size == 0)
      {
        break;
      }

      if (values[i].StartsWith(PrefixText))
      {
        output[--size] = values[i];
      }
    }
    return output;
  }

}


And that’s it! Atlas generates script code to query the web service after at least three characters have been entered into the text field.