ASP.NET UpdatePanel Javascript Callback

最后都变了- 提交于 2019-12-19 07:17:21

问题


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.


回答1:


<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




回答2:


The linked solution did not work for me. I had to:

  1. Add the following tag to my pages

    <meta http-equiv="X-UA-Compatible" content="IE=10"/>

  2. Create a javascript file, move the initialization code to the javascript file, then add a <ScriptReference Path="myfile.js"> in my <ajaxToolkit:ToolkitScriptManager><Scripts> section.

No external browser definition files. Works on VS Studio Express 2013 for Web on Windows 7 Enterprise and on 2 live Windows 2003 Servers.



来源:https://stackoverflow.com/questions/1765650/asp-net-updatepanel-javascript-callback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!