Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET UpdatePanel Javascript Callback

I came across this issue recently and thought it was really helpful. My question was, how would you call a piece of javascript after an updatepanel loads via AJAX in ASP.NET?

I needed to reinitialize a jQuery datepicker after the panel had loaded.

like image 490
a432511 Avatar asked Nov 19 '09 18:11

a432511


1 Answers

<script type=”text/javascript”>

var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_pageLoaded(panelLoaded);

function panelLoaded(sender, args){

    // Your code here

}

</script>

Essentially this is creating an instance of the PageRequestManager which handles all the UpdatePanel loading. Then ties the panelLoaded function to the pageLoaded event.

I also found this article which explains this is much more detail: http://msdn.microsoft.com/en-us/magazine/cc163413.aspx

like image 102
a432511 Avatar answered Oct 31 '22 17:10

a432511