Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have a javascript callback executed after an update panel postback?

I'm using a jQuery tip plugin to show help tips when the user hovers certain elements of the page.

I need to register the plugin events after the page is loaded using css selectors.

The problem is I'm using an ASP.NET Update Panel and after the first postback, the tips stop working because the update panel replaces the page content but doesn't rebind the javascript events.

I need a way to execute a javascript callback after the Update Panel refreshes its content, so I can rebind the javascript events to have the tips working again.

Is there any way to do this?

like image 877
tsbnunes Avatar asked Jul 20 '09 11:07

tsbnunes


People also ask

What is the difference between callback and postback?

Postback is a term that gets introduced very recently by ASP . NET programming as Dreas explained, whereas callback is more generic and has been used way before web development exists.

How do you use postback in JavaScript?

How to Raise a Postback from JavaScript? To do this, we need to just call the __doPostBack() function from our javascript code. When the above function is called, it will raise a postback to server.

Why AsyncPostBackTrigger is used in Update panel?

Use the AsyncPostBackTrigger control to enable controls to be triggers for an UpdatePanel control. Controls that are triggers for an update panel cause a refresh of the panel's content after an asynchronous postback.

What is postback trigger in UpdatePanel?

AsyncPostBackTrigger - use these triggers to specify a control within or outside of the UpdatePanel that, when clicked, should trigger a partial page postback. PostBackTrigger - use these triggers to have a control within the UpdatePanel cause a full page postback rather than a partial page postback.


1 Answers

Instead of putting your jQuery code inside of $(document).ready(), put it inside

function pageLoad(sender, args) {      ...  } 

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.

See this Overview of ASP.NET AJAX client lifecycle events

like image 164
Russ Cam Avatar answered Sep 17 '22 15:09

Russ Cam