最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ajaxToolKit autoCompleteExtender OnClientItemSelected - Stack Overflow

programmeradmin2浏览0评论

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"

发布评论

评论列表(0)

  1. 暂无评论