How Effective Is ASP.NET Partial Rendering?

Dr. Dobb's Digest October 2009

How Effective Is ASP.NET Partial Rendering?

Partial rendering -- a simple postback-based technique

By Dino Esposito


Do you agree that AJAX is a real breakthrough, making possible things that were impractical, if not impossible, before? I believe that anyone would agree to this statement.

Do you agree that AJAX is quite difficult and bothersome to implement without (but often also with) ad hoc programming tools such as libraries and controls? All in all, this statement is also hard to contradict.

Today's Web pages are cumbersome (or "rich" if you want to be polite). Such pages take a while to download and refresh; and having a significant set of interactive features, they tend to refresh quite often. The waiting time would even be valuable if only the new content could justify it. Instead, for the most part of it, the new content is just like the old content except some very small fragments. Any Web developer would agree on this point too.

However, any further perspectives and viewpoints will generate discussion -- sometimes heated -- among developers. Some developers believe that all you need is a mechanism in the Web development framework of choice that lets you refresh only the portion of the page that really requires updates. Other developers believe that to achieve this you must redesign your pages and applications from the ground up to follow the AJAX paradigm literally.

As a matter of fact, the AJAX paradigm turns out to be quite expensive to apply all the way through. For this reason, a simpler postback-based mechanism like ASP.NET Partial Rendering is an effective alternate approach. But how effective?

The idea behind partial rendering is that you wrap any portions of the page that may be updated over a postback in an ad hoc panel control -- the UpdatePanel control. When a postback occurs, some special code executes that hooks up the underlying request, and runs it asynchronously. This JavaScript code is emitted by the ScriptManager control -- the second ASP.NET AJAX control you need to have to enable partial rendering.

On the server, the ScriptManager control overrides the rendering phase and writes to the output stream only the output of the controls in the AJAX panels being really updated. As a result, only the delta of the page that has changed is returned. The JavaScript code that triggered the process receives the response and updates the DOM tree accordingly.

To evaluate the effectiveness of the process, let's review the amount of data being moved in the roundtrip.

During the upload of the request, a partial rendering operation adds some extra information not found in a regular postback. In particular, it adds an extra HTTP header and a new parameter in the form collection. Not really a big difference. The downloaded response may be significantly shorter, but some conditions affect the real size. The response is made of some fixed components -- the viewstate and other helper hidden fields such as EVENTVALIDATION -- plus variable-length content. The variable-length content contains the markup for only the portions of the page that have been updated during the request. Here are a few considerations:

In summary, there are many ways to set up a partial rendering operation within an ASP.NET page and minimize the amount of data being moved around. Does it really make a difference for the end user?

Partial rendering delivers some of the key benefits of AJAX, but it is just plain ASP.NET with a smarter and script-based management of the request. Actually, for the end user the big benefit of partial rendering is the perception of performance they experience when the page content is refreshed without any flickering in the whole page. Partial rendering delivers this AJAX benefit regardless of further optimizations.

The bottom line is that using partial rendering is effective because it neatly improves the user experience without much effort on the developer's side. Spending much time trying to further improve partial rendering by minimizing data transfer may result in tricky issues and even recommend a significant rearchitecture of the pages. Partial rendering is really effective if it is cheap to implement.