Slow performance of a GridView inside an UpdatePanel

Here is an interesting problem we ran into recently.  The customer had a large GridView that was being updated by AJAX inside on UpdatePanel and seeing bad performance.

The reason is that the Client-Side Javascript has to walk the entire DOM of the Content of the UpdatePanel to tear down the HTML DOM as the Page goes through an Asynchronous update.

First Solution

To alleviate the Expensive Stack Walks to destroy DOM Elements and its related Time Delay, the developers suggested that we remove the Unnecessary payload from the DOM of the UpdatePanel during an Asynch Postback.

The Way you would implement this is to:

1. Hook up an Event handler to the beginRequest Event .

EX:

<script language ="javascript" type ="text/javascript">
  Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(clearDisposableItems) </script>

2. Destroy an DOM Elements that you don’t want the Framework to tear down by tearing it down manually.

EX:

function clearDisposableItems( sender , args ) {
  if (Sys.Browser.agent == Sys.Browser.InternetExplorer ) {
    $get('<%=GridViewID.ClientID%>').tBodies[0].removeNode(true);
  } else {
    $get('<%=GridViewID.ClientID%>').innerHTML="";
  }
}

This gave us a slight decrease in the time taken for async Updates, about 3 seconds less.  But, we are still far away from the optimal turn-around time of a few seconds.

In a sample that I setup on my machine using about 500 rows in a GridView,  the turn-around times were in the order of sub-seconds when the GridView had text labels instead of textboxes.

When I changed the text labels to textboxes, there was an exponential jump in the time taken to process the Form even before the request was submitted to the Server.

Sub-second response times changed to 25 seconds!!

The main reason for this slow-down is due to the number of Controls that are present in the Grid.  We cannot optimize the Javascript to give good performance in this scenario.

Alternative methods

So what can we do if we need a GridView with controls?  Well, the best suggestions are:

  • Enable paging to allow the control to stay smaller but still give all the information required.
  • Change the UI to allow for an optimal number of rows that give acceptable performance.
Published 15 September 08 06:00 by Tom
Filed under: , , ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# discount furniture &raquo; Slow performance of a GridView inside an UpdatePanel said on September 15, 2008 6:01 AM:

PingBack from http://informationsfunnywallpaper.cn/?p=5314

# Quoo said on September 15, 2008 9:36 AM:

Alternative: Stop using the bloody monolith that is the GridView, and stop being lazy and implementing AJAX in performant oriented sites with an UpdatePanel.

# angry developer said on September 15, 2008 10:04 AM:

do not bring 5 million records and bind to a grid. It has been #1 problem with Datagrid. m$ft never suggest to use filter and possible search capabity to bring small dataset back

# redsquare said on September 15, 2008 11:13 AM:

surely the best option is to return json and just change the td contents rather than rebuild the thing everytime - also save bucket loads of k down the wire

# Vlad said on September 15, 2008 12:24 PM:

Use paging, for instance 100 rows inside update panel with 10 columns happens in under 2 secs.

# Ajay said on September 15, 2008 1:50 PM:

Just use custom pagination when you bind it to your gridview.  So that way you're not fetching every single record upon page change.

You can do this with all databases.

# kamii47 said on September 16, 2008 1:33 AM:

What could i do if I have update panel in Master Page.

And One of My content Page have such type of Gridview?

[I know about custom pagination but i can't do that here]

# Tom said on September 16, 2008 6:44 AM:

You could change the sql query to limit the data coming back at that level.  Or you could find another means for updating it, like caching on the client-side and not using AJAX at all for example.

# anurag chauhan said on October 16, 2008 1:51 AM:

set updatepanel property updatemode="conditional"

# Miguel said on February 11, 2009 11:41 AM:

In case anyone else gives this a shot. I was getting an "object doesn’t support this property" error on this line:

Sys.WebForms.PageRequestManager.getInstance().add_BeginRequest(clearDisposableItems)

_BeginRequest should be _beginRequest:

Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(clearDisposableItems);

It was driving me nuts for a good 10 minutes.

:-)

# Tom said on February 11, 2009 12:06 PM:

Miguel,

Thanks for catching that.  I have updated to post to reflect that.

# Julien said on March 6, 2009 7:45 AM:

It might sound obvious but if your using IE, make sure that you turn off Script Debbuging in your browser's settings. It was taking 80secs to load a table because of that !

Simple, obvious, but I didn't spot that straight away !

Won't fix DOM loading time issue but measures will be realistic though, and I might save you one or two heart attacks ;-)

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required

Search

This Blog

Syndication

Page view tracker