Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run javascript function after Postback

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

like image 639
Kimtho6 Avatar asked Nov 19 '10 09:11

Kimtho6


4 Answers

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>
like image 96
Mehdi Golchin Avatar answered Nov 08 '22 00:11

Mehdi Golchin


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

like image 27
Paddy Avatar answered Nov 08 '22 00:11

Paddy


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

like image 13
Mina Gabriel Avatar answered Nov 08 '22 01:11

Mina Gabriel


Try this:

$.ajax({
beforeSend: function(){
// Handle the beforeSend event
},
complete: function(){
// Handle the complete event
}
// ......
});
like image 5
M.Mohammadi Avatar answered Nov 07 '22 23:11

M.Mohammadi