views:

549

answers:

2

I have a simple JS function that needs to get called when AJAX call succeeds, however i don't have any control over the AJAX calls since the framework (DNN5) handles all that.

How do i call my function on AJAX success?

I use DNN5 and jQuery, if you're not familiar with DNN, just assume that all the controls on the page are wrapped in the asp:UpdatePanel.

Thank you.

+1  A: 

I'm not familiar with DNN5, but am with UpdatePanels. Can you hook into the Client events of an async postback in ASP.NET AJAX i.e. add an eventhandler to the PageRequestManager endRequest event.

As an example,

  var prm = Sys.WebForms.PageRequestManager.getInstance();

  prm.add_endRequest(EndRequest);

  // runs when async postback completes.
  function EndRequest(sender, args)
  {
  if (sender._postBackSettings.sourceElement.id) // the id of the element that raised the postback that is completing
      {
        //Do what you need to do here
      }  
  }

EDIT:

Thinking about it, I'm not sure whether this will work for you. It'll depend on how DNN5 performs the AJAX calls within ASP.NET

Russ Cam
your code is essentially the same, thank you
roman m
A: 

@Russ: just saw your answer, i'll test it, and if it works i'll accept it.

shortly after posting this question, i recalled that i had the similar problem in my previous project, so i went back and got the code from there:

<script type="text/javascript">

Sys.Net.WebRequestManager.add_completedRequest(onComplete);


function onComplete(sender, args) { //call JS here
}

function pageUnload() {
    Sys.Net.WebRequestManager.remove_completedRequest(onComplete);
}

</script>
roman m