3

I am trying to implement an autoCompleteExtender into my project. Currently I am using the OnClientItemSelected property to call a javascript on the client side. Is there a way (using another property or some other code) that will let me call a method in the code behind when the user selects an option?

theNoobProgrammer
  • 924
  • 2
  • 15
  • 34

2 Answers2

1
function AutoCompleteEx_OnClientItemSelected(sender, args) {
     __doPostBack(sender.get_element().name, '');
}

On server side handle TextChanged event of extended textbox.

Yuriy Rozhovetskiy
  • 22,270
  • 4
  • 37
  • 68
1

For this you need to return the list from web service method with ID and Text

Here "lst" is the actual list with data from your data source.

List<string> items = new List<string>(count);
        for (int i = 0; i < lst.Count; i++)
        {
            string str =AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(lst[i].Text,Convert.ToString(lst[i].IDValue));                
            items.Add(str);

        }
        return items.ToArray();

Then simple javascript

function GetID(source, eventArgs )
    {
        var HdnKey = eventArgs.get_value();
        document.getElementById('<%=hdnID.ClientID %>').value = HdnKey;
    }

and dont forget to set the attribute in auto complete extender OnClientItemSelected="GetID"

Bhavin Mistry
  • 85
  • 1
  • 3