在回发后运行 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 11:27:40  来源:igfitidea点击:

Run javascript function after Postback

javascriptasp.netajax

提问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);

http://msdn.microsoft.com/en-us/library/asz8zsxy.aspx

http://msdn.microsoft.com/en-us/library/asz8zsxy.aspx

回答by Mehdi Golchin

You can use endRequestevent 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()

Read this by Dave Ward

阅读戴夫·沃德 (Dave Ward) 的这篇文章

回答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