Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to call client-side Javascript function after an UpdatePanel asychronous (Ajax) request is over

How to call client-side Javascript function after an UpdatePanel asychronous (Ajax) request is over

Scheduled Pinned Locked Moved ASP.NET
javascriptphpcomsysadminhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zeemalik
    wrote on last edited by
    #1

    If you are using AJAX then the only way i have found yet to give an alert to a user on return to the Asynchronous post back is to add an "end request" handler to the PageRequestManager. In this way you can tell the request manager to run a javascript function on returning from a Asynchronous post back event of AJAX. Code for doing this is : function load() { Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler); } where "EndRequestHandler" will be the name of your javascript function you want to call. Call the above function in Onload event of tag: function EndRequestHandler() { alert("You record has been saved successfully"); } Now If you want to give a different message based on your logic in server side code (code behind) then you can use a server side Hidden Field: Set its value in server side code on Asychronous Post Back: Protected Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCreateSample.Click If condition Then hdnValue.value = "do this" Else hdnValue.value = "do that" End If End Sub Now you can check the value of this Hidden Field in your Client Side EndRequestHandler function and give a different alert to user based on its value: function EndRequestHandler() { if (document.getElementById('<%= hdnValue.ClientID %>').value == "do this") { alert("You record has been saved successfully"); } else { alert("There is an error"); } } http://zeemalik.wordpress.com/

    To do what can be done is a Intelligent Job and to do what should be done is a Genious Job done is a Genious Job

    S 1 Reply Last reply
    0
    • Z zeemalik

      If you are using AJAX then the only way i have found yet to give an alert to a user on return to the Asynchronous post back is to add an "end request" handler to the PageRequestManager. In this way you can tell the request manager to run a javascript function on returning from a Asynchronous post back event of AJAX. Code for doing this is : function load() { Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler); } where "EndRequestHandler" will be the name of your javascript function you want to call. Call the above function in Onload event of tag: function EndRequestHandler() { alert("You record has been saved successfully"); } Now If you want to give a different message based on your logic in server side code (code behind) then you can use a server side Hidden Field: Set its value in server side code on Asychronous Post Back: Protected Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCreateSample.Click If condition Then hdnValue.value = "do this" Else hdnValue.value = "do that" End If End Sub Now you can check the value of this Hidden Field in your Client Side EndRequestHandler function and give a different alert to user based on its value: function EndRequestHandler() { if (document.getElementById('<%= hdnValue.ClientID %>').value == "do this") { alert("You record has been saved successfully"); } else { alert("There is an error"); } } http://zeemalik.wordpress.com/

      To do what can be done is a Intelligent Job and to do what should be done is a Genious Job done is a Genious Job

      S Offline
      S Offline
      SABhatti
      wrote on last edited by
      #2

      your post is ambiguous. Are you trying to ask or tell? If you are asking about how to call a javascript function after updating a update panel then use the scriptmanager e.g. ScriptManager.RegisterStartupScript(idOfTheUpdatepanel, GetType(UpdatePanel), "scriptkey", javascriptFunctionOrScriptToBeCalled, True);

      -----

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups