How to call Javascript function after an UpdatePanel asychronous request to ASP.Net page

If you are using UpdatePanel and you want to call a javascript function after content refresh in update panel, You can use below way to do it easily,

In Page body tag , call a function RefreshContent()

<body   onload="RefreshContent()">

<script type="text/javascript">

function RefreshContent()
{  
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
}

function EndRequestHandler()
  {
   alert("Add your logic here" );
  }

</script>

If you  are using Master page then assign a  id to body tag and also add runat="server"
<body   id="body" runat="server">

 protected void Page_Load(object sender, EventArgs e)
    {
//For a single specific page only, use below url check and match code

   if (Request.RawUrl.ToLower().Contains("Your Page Name in Lower Case"))
       {
           body.Attributes.Add("onload", "RefreshContent()");
       }
}

 

Related Alrticles

FREE!!! Registration