Sunday, April 17, 2011

jQuery Autocomplete in ASP.net MVC doesn't work when the control created in Ajax way

I am running an issue, could you help me out with your knowledge..?

Basically, this autocomplete extension of jQuery depends onto the ready method of the jQueryLibrary. (I am not 100% sure what it does actually, but I can guess it checks wheather the DOM has been loaded, if loaded it does something as an regular "onload" event handler).

Now, I have an ASP.net MVC application where I am using Ajax to render a partial view (an ascx file) and that file contains the autocomplete textbox.

As the DOM has been already loaded and I am now modified the DOM with the content of the ascx file in an Ajax fashion, my text boxes into the ascx are not doing anything autocompletion. What could be an alternate or workaround of this problem..? Even I am a bit curious why it's not working..?

Any idea would be greatly appreciated.

Have a nice day

From stackoverflow
  • you need to load the autocomplete function again as like you said the new items in the dom have come after the jquery already loaded. You can either put the jquery function in the ascx (simple way) or force the jquery to run on the DOM again which may cause unintended results.

  • Jeremy thanks for your reply. Here is my ascx code. I didn't understand what you said by ""..could you be so kind explaining a bit more..? thanks a lot!

    here is an image that shows my user controls code. http://img10.imageshack.us/img10/6845/75246857.jpg

0 comments:

Post a Comment