JQuery Autocomplete will lose text on AutoPostBack

I have a jQuery autocomplete field on an ASP.Net web form and everything has been working fine so far. I also have a DropDownList that I need to run onSelectedIndexChanged using AutoPostBack.

When I changed my code to make AutoPostBack, a text field that has jQuery autocomplete back in. However, if I look at the source of the page, the text is in the text box. If I submit the form now, the page will send an empty field. My Google-Fu is weak on this since I could not come up with a workaround for it.

Has anyone encountered such problems when the Autocomplete field was obscured by AutoPostBack, and how did you manage?

I can publish the code if it is really necessary, but I would need to misinform it before I can, due to company policy.

+3
source share
2 answers

How is the autocomplete field initialized? Is it installed on an empty line either when loading a page from the server, or through the autocomplete of the jQuery plugin on document.ready?

If the plugin source code points to a blank line in document.ready, try the following:

// Store current textbox value in a var
var temp = $('#mytextbox').val();

// Initialize the autocomplete plugin (winging it on the syntax)
$('#mytextbox').autocomplete();

// Reset the value of the textbox.
$('#mytextbox').val(temp);
+1
source

If you use the jQuery Autocomplete 1.1 plugin, * Edition: $ Id: jquery.autocomplete.js 15 2009-08-22 10: 30: 27Z joern.zaefferer $

"autoPostBackSelection: false" Ex:

$.Autocompleter.defaults = {
    inputClass: "ac_input",
    resultsClass: "ac_results",
    loadingClass: "ac_loading",
    minChars: 1,
    delay: 400,
    autoPostBackSelection: false,
    ...

"return true" selectCurrent().

if (options.autoPostBackSelection == true) {
        __doPostBack($input.id, "");
      }

:

selectCurrent() {     ...       if (options.autoPostBackSelection == ) {         __doPostBack ($ input.id, "");       }       return true;     }

0

Source: https://habr.com/ru/post/1707722/


All Articles