Redisplay results list on AutoCompleteExtender thr

2019-07-22 04:36发布

问题:

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);
}