Wednesday, March 28, 2012

Why slow UI with AJAX?

I am working on a page that displays paged ResultSet from a database. I created the page without AJAX update panels. Later I added those to ajaxify my application. The problem is when I change pages in my GridView the time it takes for it show the new results (using Asynchronous postback) is about 4 secs more then a regular postback.

Does any one know why it is slow. I usedfiddler tool to check the response size and Asynchronous postback does come back with less number of bytes but why slow UI update?

Thanks for your help.

The thing that will effect your AJAX postback the greatest is the size of your ViewState.

Comment out your update panels & script manager and then enable tracing for your page.<% @.Page Trace="True" %>The trace information will show you exactly how large your ViewState is for that page. Try paging through your GridView and see if you ViewState size grows as you page. Even if the size doesn't grow, if the initial ViewState size for your page is very large, it will cause long delays between AJAX postbacks. If you do find that your ViewState is huge, or it grows between postbacks, try to figure out which controls you can disable the ViewState for (EnableViewState="False") or what might be causing your ViewState bloat.

Just as an FYI, I have used UpdatePanels with GridViews in many different cases without a problem. I did have to tune the ViewState for some of the pages I made to speed things up, but it can definitely be done and it works great.

-Aaron


I am totally agree withSchnieds , that you have to disable the viewstate wherever it is not necessary..

Do one more thig also..try to set <compilation debug = "false" > in web.config

Hope it will help you.Smile


Thanks for your replies. I tried to turn the viewstate off for the gridview but then my pagging gets all screwed up. I have a dynamic paging option where user can select the number of results displayed per page. When I turn off the viewState it gets set to the default value (which is 14) and the page index gets set to 1.

Any ideas?

P.S.: I do have the <compilation debug="false" />


You probably won't be able to disable the ViewState for your GridView, but you may be able to disable it for other controls on your page and decrease the overall ViewState size.

Turn on tracing as I suggested, figure out what control(s) have a large ViewState and look for the other things I mentioned in my previous post. You should be able to determine what is causing your ViewState bloat very easily with the tracing turned on.

-Aaron

No comments:

Post a Comment