views:

730

answers:

8

I have a simple aspx page with a GridView control. I'm loading the GridView with search results after the click of a button. Everything works, but the HTML rendering on the browser is very slow in IE with a result set > 2000 (works fine in other browsers.) I realize it's slow due to the record count, but is there a way I can make it faster? (I don't want to use paging.)

Oddly, it's slow only when it's hosted on Windows 2003 server. It works fine on my localhost, but on either the test site or production, the problem occurs. If I remote desktop to my test server and run it locally there, the page loads fine. The problem only occurs when I run the server hosted application from my local machine.

How can I resolve this issue?

+1  A: 

Some simple suggestions, turn off the view state on that control. Also are you using MS AJAX, that can also cause problems. Take it out of the update panel if you are.

Al Katawazi
Thanks for the reply. The ViewState was already turned off. I'm not using AJAX on that page. That page has nothing except a simple GridView control....Please help.
+7  A: 

It works fine when transferring from localhost, as the network bottleneck is not there -- some browsers wait for the entire table to be transmitted before attempting to render - especially when not using fixed column widths (which can speed up performance); Have you looked at the size of the entire generated page?

Rowland Shaw
In the "View Source", there is not much ViewState. There is just the HTML table generated with somewhere like 2500 rows. What do you think I should do to make it little faster? Thank you.
I saved the "View Source" file and it is 1.59 MB.
Ouch. that's very big. maybe you should consider paging the results
Rowland Shaw
Also make sure that the source is compressed when it's transmitted across the network.
David
+1  A: 

If you need ViewState on the control, you can reduce the ViewState impact the GridView has on the page by disabling the ViewState on each row in the PreRender event:

  Private Sub grid_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles grid.PreRender

    For Each item As DataGridItem In grid.Items
      item.EnableViewState = False
    Next

  End Sub
Brandon Montgomery
A: 

Perhaps more information is needed.

how large is the generated html? Are there many external resources (e.g. css/js/)? Are there many images?

Canton
There is not much ViewState in the "View Source". There is a generated HTML table with somewhere like 2500 rows. There is one external css file and couple of small javascript functions inside the head section. There is also a checkbox column in the GridView that allows the user to select row.
I saved the "View Source" file and it is 1.59 MB.
+1  A: 

If you're not already compressing the HTTP Response, you should look into doing that.

  • Look at Yslow for FireFox (start here)
  • Compress your response with standard gzip/deflate compression
  • Do what you can to reduce the amount of data in your GridView. Elminate unecessary columns, etc.
  • Turn off viewstate
  • Use jsmin to reduce the size of your JavaScript files (if any)
  • Reduce the size of your CSS (if any)
Terrapin
A: 

In short, do custom paging, so that it won't load all items on page load. Linq Data Source does it for you.

ercu
A: 

Why don't you want to use paging? 1.6 MB is a lot for the html of a page.

Considering you already disabled viewstate, look into reducing the amount of html by:

  • Remove unnecessary columns
  • Use only css to style the gridview. The idea being not to repeat the same visual rules all over the HTML.
  • Avoid unnecessary markup in the columns. Look into any template columns you may have, and simplify the HTML in there (also using css to style it).
eglasius
A: 

Since the network is the bottleneck in this case, try to minify the resulting HTML. Apparently, the weight of each grid row is about 640 bytes on average (2500 records generate 1.6M payload). See if you can reduce it by removing unnecessary spaces and shortening any HTML elements IDs. Move styling, if any, from the grid to CSS, as was suggested before. If grid renders any URLs (e.g. “href” in anchors or “src” in images) try to shorten them. Also, if HTML rendered by GridView is not optimal see if you can render yourself. In order to estimate the anticipated page response time in production, factor-in your average user network speed (that may be different from the network speed of your machine).

If none of the above produce satisfactory result you may check the solution that we have – ASP.NET accelerator called Web Stimulus. It partially executes ASP.NET page code on the client to render the HTML on the client computer. Typical traffic reduction is 10-20 times with minimal code change.

Vadim Kleyzit