How do i run a javascript event after a postback within an updatepanel
For use within an UpdatePanel i would use the ScriptManager.RegisterStartupScript
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>
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
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
Try this:
$.ajax({
beforeSend: function(){
// Handle the beforeSend event
},
complete: function(){
// Handle the complete event
}
// ......
});