Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm using the jQuery autocomplete and this works perfect. But when I do a postback, it looks like the page "forgets" that there is an autocomplete on the textbox.

Important to know: this textbox is within an updatepanel!

Anyone who knows how to solve this one? Thanks!

share|improve this question
    
I guess the updatepanel recreate the DOM, so jQuery "lost" its binding. Can you move the jquery declaration within the update panel ? –  Steve B Jun 27 '12 at 8:59

1 Answer 1

up vote 3 down vote accepted

This is because the UpdatePanel updates all the content WITHIN the UpdatePanel itself, meaning it recreates the DOM within that, excluding all javascript from outside the Panel.

It has to be pointed out that moving the javascript within the UpdatePanel will not help.

You'll have to use the Sys.WebForms.PageRequestManager.getInstance(); in order to make sure that all javascript is processed again after every change or update on the current page.

Example:

<script type="text/javascript">
var requestManager = Sys.WebForms.PageRequestManager.getInstance();
requestManager.add_beginRequest(BeginRequestHandler);
requestManager.add_endRequest(EndRequestHandler);

function BeginRequestHandler(sender, args) {
    // Add your logic here
};

function EndRequestHandler(sender, args) {
    // Add your logic here
    // This is where you trigger all the functions needed AFTER the DOM has been loaded
};
</script>

More info here

Hope this helps :)

share|improve this answer
    
I don't know if this works, but for now I've set an onfocus javascript event on my textbox where I bind the autocomplete each time to the textbox. For now, I'll accept your solution... –  Ruben Herman Jun 27 '12 at 10:03
    
@RubenHerman Let me know if it worked for you :) –  Daniel Ziga Jun 27 '12 at 10:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.