幕后的UpdatePanel

The knowledge I have about UpdatePanel is

  1. They use Ajax requests to work asynchronously.
  2. They perform a partial postback.

Now recently I was working on Ajax requests too using $.ajax() method of jQuery when I found some difference about Ajax requests made by me and Ajax requests made by UpdatePanel which are

  1. UpdatePanel's Ajax request perform full page life cycle but my Ajax request calls only that particular method which I have supplied to be called.
  2. Methods called by UpdatePanel doesn't need to be tagged as WebMethod but methods called by my Ajax request has to be WebMethod.

I searched web to get details about these differences but doesn't found any resource, Can someone tell me whats the difference between Ajax calls made by me and by UpdatePanel or more specifically hows those differences made and what special tricks are played by UpdatePanel to achieve that functionality ?

I liked this question mate +1

Basically the evil UpdatePanel is the root of all evil. Sadly it is =(. The update panel behind the scenes raises async postbacks to the server, but to fully understand what happens, you need to understand the UpdatePanel goal

The UpdatePanel was designed to work with the ASP.Net web forms, these controls have to go through the whoooole ASP.Net page life-cycle in order to work correctly, therefore, they need the whoooole page ViewState. So every time you perform a post back using an UpdatePanel the whole page viewstate will be sent to the server back and forth even when you only want to partial render a small part of your page.... sucks. Why did Microsoft created this monster? I think it was because back 5-6 years ago (or more) AJAX was not so popular as it is today. Another reason is that Microsoft wanted to provide a framework to write AJAX calls in a simple way, but without losing the power of the web controls.

So with this in mind, the difference between an UpdatePanel and an AJAX call, is simply:

The AJAX call sends only the data needed by the server method and it returns just the required data. The performance of using pure AJAX calls is impressive.

but methods called by my Ajax request has to be WebMethod.

That's partially true, I mean there are different ways to expose methods from the server:

  • Using traditional Web Services - Script services (ASMX)

  • Using PageMethods (static methods on your ASPX pages)

  • Exposing WCF services

  • Exposing WCF REST services

  • Using WEB API

  • Using MVC controller's actions

  • Using custom HttpHandlers returning a specific content type like JSON

  • etc

At the end the result is the same, no matter what approach you use to expose server methods when consuming them with pure AJAX calls you will have to face the following if you are using web forms:

If you want to use pure AJAX calls, then you should consider moving to MVC because in web forms you will lose the power of the web controls, in other words your development would be more difficult

They perform a partial postback.

No, update panels perform a full postback, they just perform a partial update on the page.

UpdatePanel's Ajax request perform full page life cycle but my Ajax request calls only that particular method which I have supplied to be called.

Precisely, the Update panel performs a full postback. Highly inefficient.