Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between IsPostBack, IsAsync and IsCallback?

I was writing code in Page_Load and I used IsPostBack in the first place but then I came across with IsAsync and IsCallback properties. I started to think and they look like somewhat the same. From google I found some information:

  1. IsPostBack is true when the page is posted via a form method, I agree 100%.
  2. IsCallBack is true when the page has been called back from an AJAX call, Then for what purpose IsAsync is for?
    from MSDN "IsCallBack: Gets a value that indicates whether the page request is the result of a callback."
  3. IsAsync when an ASP.net AJAX partial update is made ,its an Asynchronous postback.

However I still have some questions:

  1. What is a callback and how it is different from a postback.
  2. Clearly differentiate among IsPostBack, IsAsync and IsCallback.
  3. Currently I'm working on a WebApp, which can perform postBack through jQuery Ajax. So to identify the jQuery Ajax I should use IsPostBack.

Useful links:

Difference between IsCallback and IsPostback

like image 210
Owais Qureshi Avatar asked May 22 '12 20:05

Owais Qureshi


1 Answers

The IsAsync is independent of the type of request made by the client and its used to identify a page that is processed asynchronously as described in the documentation:

Gets a value indicating whether the page is processed asynchronously.

You can read more about asynchronous pages in this MSDN Magazine article Asynchronous Pages in ASP.NET 2.0.

The IsCallback is used to identify a client callback, see Implementing Client Callbacks Programmatically Without Postbacks in ASP.NET Web Pages and finally the IsPostback identifies a request that resulted from the submission of the form associated with the page. The IsPostback by itself cannot be used to identify a postback that will fully render the page from one that will do a partial rendering, for example, if you are using an UpdatePanel.

In order to identify a postback request that will only perform partial rendering you will need to check that IsPostback is true and ScriptManager.GetCurrent(this.Page).IsInAsyncPostBack is also true.

Also of interest to this topic How to: Determine How ASP.NET Web Pages Were Invoked.

like image 108
João Angelo Avatar answered Sep 29 '22 03:09

João Angelo