views:

180

answers:

2

Inside a web application that we are developing, there is a time in where the user commits a search by providing some parameters (it's a reservation system, so "parameters" = 2 dates).

A hidden table (or, better, empty) is then filled with the results of the query.

Now comes my problem: is it better to do an AJAX call to a WebMethod, or just let the "Search" button inside an UpdatePanel and update it server side?

In this post, Encosia points out that everything in the panel is updated each time an asynchronous postaback is made.

So, given the fact that this application has to be as fast as possible, and should use the lowest amount of bandwidth, i went for the AJAX approach.
In this way i lowered it from 40-60KB to ~1KB (MAX!) each search.

The execution is "Search button click" -> Ajax call to WebMethod -> JSONed result read and JQuery HTML-injected inside the table.

There are however some problems with this approach, with the bigger being hard to maintain code (client-side performance is not a big problem, it takes ~ 12ms to build the table).

+1  A: 

I don't think I'm seeing the question here.

UpdatePanel is very easy to use/abuse/maintain but effectively posts back the whole page asynchronously.

AJAX may be slightly harder to maintain/involves more setup/boilerplate code, but sends and receives less data and therefore uses less bandwidth. It should be more performant than UpdatePanels, but whether this is significant depends on a number of different factors (number of controls, page size, ViewState size, etc).

The choice is whatever fits your situation best really. What are the feature priorities of the application? If performance/bandwidth ranks over maintenance, go for AJAX. If maintenance and speed of development is importnant, maybe the choice is UpdatePanel. If this is an Intranet Application, I'd probably be less concerned about using UpdatePanels.

Russ Cam
A: 

If you have a choice, go ahead and use PageMethods with jQuery. You will be much happier in the long run. UpdatePanel is going to get better with ASP.NET 4.0, but its still inferior to to jQuery and PageMethods.

rick schott