Hcabnettek Hcabnettek - 6 months ago 29
Javascript Question

How can I run some javascript after an update panel refreshes?

I have a pageLoad function which sets some css on an .ascx control that I cannot change. On page load everything is fine, but when an update panel updates the control, my css is no longer applied. How can I rerun my function after the page updates?

$(function() {
$("textarea").attr("cols", "30");
$("input.tbMarker").css({ "width": "100px" }).attr("cols","25");
});


This obviously only runs on the initial page load. How can I run it after an update?

Answer

Adding an add_pageLoaded handler can also work.

Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(PageLoadedHandler);

Note: the handler will fire for any callback, but you can use sender._postBackSettings.panelID to filter when you want your function called.

More samples:

Comments