在Postback之后运行javascript函数

Kim*_*ho6 38 javascript asp.net ajax

如何在updatepanel中回发后运行javascript事件

Meh*_*hin 71

你可以使用的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>
Run Code Online (Sandbox Code Playgroud)


Pad*_*ddy 25

您可以使用ClientScriptManager在重新加载时调用函数:

ClientScriptManager.RegisterStartupScript(this.GetType(), "AKey", "MyFunction();", true);
Run Code Online (Sandbox Code Playgroud)

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


Min*_*iel 11

只是

<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>
Run Code Online (Sandbox Code Playgroud)

每次触发Button1时,将继续调用pageLoad()

阅读戴夫沃德


M.M*_*adi 5

尝试这个:

$.ajax({
beforeSend: function(){
// Handle the beforeSend event
},
complete: function(){
// Handle the complete event
}
// ......
});
Run Code Online (Sandbox Code Playgroud)