Channels ▼
RSS

Parallel

How Effective is ASP.NET Partial Rendering?



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:

  • For pages with a very large viewstate, the difference is not significant because the large viewstate counts more than anything else. The viewstate is always returned entirely and it is never limited to only the controls really updated.
  • To get the most out of partial rendering, you need to optimize your use of the viewstate.
  • The size of the returned markup depends on the number and placement of UpdatePanel regions. Multiple but smaller UpdatePanels are preferable because they ould allow you to better restrict the area subject to dynamic updates. If a button doesn't change during a request, there's no reason for including it in an UpdatePanel, even though the same button is responsible for triggering the refresh of that UpdatePanel.
  • Ideally, you should try to partition your page in non-overlapping UpdatePanel. However, this is not always possible.

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.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 

Video