Blog

Aborting ASP.Net PageMethod Requests

ASP.Net Ajax features are very good, even great if you consider the useful integration with other ASP.Net constructs. PageMethods are one of the easiest ways to implement an AJAX call without too much trouble or the need to implement a complete web service page if you’re only going to use this particular Ajax call from within this page.

But unlike web service references, aborting a PageMethods request isn’t straightforward at all. The problem is, unlike web service JS wrappers, when you call PageMethods.YourMethod(…) it doesn’t return anything (its return type is basically a void). This is surprisingly stupid in my opinion, but maybe there are reasons I’m simply not aware of.

So, in order to be able to abort a PageMethods request you need 2 things. The first, is a reference to the request being executed which can be retrieved and used like this:

var request = PageMethods._staticInstance.YourMethod(params, onSuccess, onFail);

This time the request variable will be correctly retrieved. But to properly abort the request you still need to know 1 more thing:

var executor = request.get_executor();
if(executor.get_started())
executor.abort();

That’s it, you need the executor object to access the current running request, and get_started() is just a check to make sure that: a) it has started the request already; b) it’s not done yet;

Not as simple as it should be, but not a huge work load either. Hope it helps.

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Tags: , ,

4 Responses to “Aborting ASP.Net PageMethod Requests”

  1. […] Read more here:  Aborting ASP.Net PageMethod Requests « Alexandre Gomes […]

  2. Olena says:

    Thank you very much!
    I’ve already killead a half of my day and would probably kill more if didn’t come across your web-site :)
    You saved a lot of time :)

  3. Trevor Feldman says:

    Thank you – you are a lifesaver! Your information helped me solve the problem (after almost a day of searching) of why my app was hanging up IE 6 when a popup window was closed before pending AJAX requests were completed.

  4. Vijay says:

    Thanks …your solution helped us a lot..!!:)

Leave a Reply

For spam filtering purposes, please copy the number 3849 to the field below: