Skip to content


Cancel previous Ajax requests on new request

If you are using ajax in web application , then there might be possibility that user does repetitively action such as click on button more than once which sends same asynchronous requests for every single click,
Before completing first request, another request for the same functionality is get sent and so on…

Here is the simple solution that helps to cancels previous ajax request,

Copy following two java scripts functions on page. it will cancel previous asynchronous requests. It works in asp.net ajax.

function pageLoad()
        {
Sys.WebForms.PageRequestManager.getInstance( ).add_initializeRequest(cancelPostBack);
         }
function cancelPostBack(sender, args)
        {
if (Sys.WebForms.PageRequestManager.getInstance( ).get_isInAsyncPostBack())
            {
              args.set_cancel(true);
            }
        }
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • StumbleUpon
  • Twitter
  • Yahoo! Buzz

Posted in Ajax, Asp.net, Javascripts.

Tagged with , , .


One Response

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Continuing the Discussion

  1. Asp.net Ajax Events | amolwable.com linked to this post on September 28, 2009

    [...] initializeRequest: can be used to cancel a postback. [...]



Some HTML is OK

or, reply to this post via trackback.