admin管理员组

文章数量:1431997

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?

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?

Share Improve this question asked Aug 7, 2012 at 14:22 theNoobProgrammertheNoobProgrammer 9323 gold badges15 silver badges34 bronze badges
Add a ment  | 

2 Answers 2

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

On server side handle TextChanged event of extended textbox.

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 plete extender OnClientItemSelected="GetID"

本文标签: javascriptajaxToolKit autoCompleteExtender OnClientItemSelectedStack Overflow