views:

188

answers:

3

Hello. I am using the AutoCompleteExtender on a commercial site. My problem is the users are quickly typing in part of a word and immediately pressing "Enter" which causes the AutoComplete control to NOT come back with a list of suggestions. For example, if my database has the phrase "Texas, United States" in it but the users just type "Texas" quickly followed by Enter then the dropdown list does not appear.

What I would like is for the AutoComplete control to ignore the fact the user has pressed Enter and go and fetch the suggested data anyway. (The ultimate would be if it ignored Enter when there was currently no list, but selected an item when there was a list).

I can simulate this exact problem by going to the samples section of this Microsoft ASP.NET site and typing in some characters very quickly followed by 'Enter'.

Please could someone tell me what I need to do?

Thanks, Martin

A: 

hey try jquery or yui autocomplete extender ... It will be lightning fast...

Pandiya Chendur
No, it is not the speed I am after as AJAX Autocomplete is fine. It is the fact that when the user presses "Enter", the list does does not appear.
A: 

I've hacked around this problem before with an extra keydown handler on the textbox that is the target of the auto-complete. Replace this._autoCompleteBehavior in the snippet below with a reference to your instance of AutoCompleteBehavior (obtainable via $find() and the BehaviorID). The idea here is to force the auto-complete behavior to think it needs to perform a lookup by calling _onTimerTick(), which executes after the typing delay has expired. By default the typing delay gets cancelled by hitting the enter key, so this just forces the lookup anyway on enter or tab.

Disclaimer: my hack references "private" members of the AjaxControlToolkit code (stuff that starts with underscore is "private"), so it is probably not guaranteed to be future-proof.

_searchTextbox_keydown: function(e)
{
    var key = e.keyCode || e.rawEvent.keyCode;

    // If the user hits enter or tab before the auto complete popup appears, force the autocomplete lookup at that moment.        
    if ((key === Sys.UI.Key.enter || key === Sys.UI.Key.tab) && this._autoCompleteBehavior._currentPrefix != this._autoCompleteBehavior._currentCompletionWord())
    {
        this._autoCompleteBehavior._onTimerTick(this._autoCompleteBehavior._timer, Sys.EventArgs.Empty);

        e.preventDefault();
    }
}
Jason
A: 

Thanks Jason, That's a really good and easy-to-use answer and does the trick. Thank you so much for your answer! Martin