Redisplay results list on AutoCompleteExtender through javascript

为君一笑 提交于 2019-12-24 04:54:08

问题


I have a working AutoCompleteExtender implementation.

What I want, is that if I have exited the text box, and the list of items have dissappeared, I want to re-display the list from javascript code without having to write something in the text box again (just redisplay list based on current filter value in text box by click on a button or something). I know how to get the AutoCompleteExtender Behaviour object from code, so all I need is to know the javascript API on that object that enables me to redisplay the list.


I have tried this as suggested in the comments on this answer, but not working:

AutoCompleteEx.showPopup();

I have also tried this as suggested in this answer, but not working:

AutoCompleteEx._onTimerTick(AutoCompleteEx._timer, Sys.EventArgs.Empty);

EDIT:
After some investigation in the back end code used by the AutoComplete, I think maybe the problem is that once shown, it checks on future calls if the value in the search box has changed since last time, and if not it doesn't show it again. I have not found out how to come around this. I have tried different approaches to reset the value, and then set the value again, but with no success.


回答1:


Enjoy :). That's was an interesting task.

function redisplayAutocompleteExtender() {
    var extender = $find("AutoCompleteEx");
    var ev = { keyCode: 65, preventDefault: function () { }, stopPropagation: function () { } };
    extender._currentPrefix = "";
    extender._onKeyDown.call(extender, ev);
}

Or you can set EnableCaching property to true on extender and use script below. This solution allows to avoid additional web service call.

function redisplayAutoComplete() {
     var extender = $find("AutoCompleteEx");
     var textBox = extender.get_element();
     textBox.focus();
     var showSuggestions = function(){
          extender._update.call(extender, textBox.value, extender._cache[textBox.value], true);
     };
     setTimeout(showSuggestions, 0);
}


来源:https://stackoverflow.com/questions/8269393/redisplay-results-list-on-autocompleteextender-through-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!