Run javascript function after Postback

后端 未结 5 1008
孤独总比滥情好
孤独总比滥情好 2020-11-29 03:54

How do i run a javascript event after a postback within an updatepanel

相关标签:
5条回答
  • 2020-11-29 04:31

    For use within an UpdatePanel i would use the ScriptManager.RegisterStartupScript

    0 讨论(0)
  • 2020-11-29 04:36

    You can use endRequest event of 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>
    
    0 讨论(0)
  • 2020-11-29 04:40

    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

    Read this by Dave Ward

    0 讨论(0)
  • 2020-11-29 04:44

    You can use the ClientScriptManager to make a call to a function on the reload:

    ClientScriptManager.RegisterStartupScript(this.GetType(), "AKey", "MyFunction();", true);
    

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

    0 讨论(0)
  • 2020-11-29 04:44

    Try this:

    $.ajax({
    beforeSend: function(){
    // Handle the beforeSend event
    },
    complete: function(){
    // Handle the complete event
    }
    // ......
    });
    
    0 讨论(0)
提交回复
热议问题