David Coughlan - Curriculum Vitae
AJAX - AutoComplete example

Plaque Search


Type two or more characters into the textbox below and a list of suggested names will be displayed containing those characters.


Description

Ajax Asynchronous Postbacks

In the above example, the AJAX AutoComplete extender calls a webservice in the background to retrieve possible suggested plaque names which contain the text that you type, as you type it. The minimum number of characters required is two, so nothing will happen when you type the first character.

Webmethod code

Using a simple XML file and Linq select statement

    [WebMethod]
    public string[] GetCompletionList(string prefixText, int count)
    {
        XDocument doc = XDocument.Load(Server.MapPath("~/AutoComplete/BluePlaques.xml"));
        var result = from e in doc.Descendants("marker")
                     where e.Attribute("label").ToString().ToLower().Contains(prefixText.ToLower())
                    select (string)e.Attribute("label");
        return result.ToArray();
    }    
        
Copyright © 2002-2012 David Coughlan. All Rights Reserved.  Contact  David Coughlan