在回发后运行 javascript 函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4223837/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Run javascript function after Postback
提问by Kimtho6
How do i run a javascript event after a postback within an updatepanel
我如何在更新面板内回发后运行 javascript 事件
采纳答案by Paddy
You can use the ClientScriptManager to make a call to a function on the reload:
您可以使用 ClientScriptManager 在重新加载时调用函数:
ClientScriptManager.RegisterStartupScript(this.GetType(), "AKey", "MyFunction();", true);
回答by Mehdi Golchin
You can use endRequest
event of PageRequestManager
.
您可以使用endRequest
的事件PageRequestManager
。
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button runat="server" Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
<script type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function (s, e) {
alert('Postback!');
});
</script>
回答by Mina Gabriel
Simply
简单地
<script type="text/javascript">
function pageLoad() {
}
</script>
<asp:ScriptManager runat="server" />
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:Button runat="server" ID="Button1" />
<asp:Literal runat="server" ID="TextBox1" />
</ContentTemplate>
</asp:UpdatePanel>
pageLoad() will then continue to be called each time Button1 is triggered
然后每次触发 Button1 时都会继续调用 pageLoad()
回答by M.Mohammadi
Try this:
尝试这个:
$.ajax({
beforeSend: function(){
// Handle the beforeSend event
},
complete: function(){
// Handle the complete event
}
// ......
});
回答by Tim B James
For use within an UpdatePanel i would use the ScriptManager.RegisterStartupScript
为了在 UpdatePanel 中使用,我将使用ScriptManager.RegisterStartupScript