I have a button that is within an updatepanel control. The button's click event has a function defined for it through JQuery. Once the async postback completes the JQuery event fails to fire when the button is clicked subsequently. What do I need to do to correct this behavior and maintain the JQuery event attachment to the button's click event once it has been refreshed asynchronously?
+2
A:
put your jquery event handler binding inside the following function
function pageLoad(sender,args) {
// binding code here, for example
$('#button').click(function(e) {
// do something when the click event is raised
});
}
pageLoad
is executed after every postback, synchronous or asynchronous. pageLoad
is a reserved function name in ASP.NET AJAX that is for this purpose. $(document).ready()
on the other hand, is executed only once, when the DOM is initially ready/loaded.
Russ Cam
2010-01-04 20:15:12
Can you flesh this code sample out more please? Thanks!
Achilles
2010-01-04 20:17:01
I've added an example event handler. The "magic" is in the function name `pageLoad`, which is a reserved function that will execute when the page posts back, syncrhonously or asynchronously. It's analogous to setting up a function to execute using `Sys.Application.add_load(handler);`
Russ Cam
2010-01-04 20:22:35
Thank you very much, just implemented this and it works great! +1
Achilles
2010-01-04 20:30:02