Wednesday, March 28, 2012

Dial-up accounts using AJAX

I don't know if there is an answer to my question, but here goes:

I have an Ajax page that uses an ASP.Net 2.0 GridView control. When I test the page on my development computer (where the server is the local host) it takes about 15 seconds to load. Several portions of the page are configured for partial page updates using Ajax and these updates take between 2 to 4 seconds which is acceptable.

When I test the same page on a remote server using a dial-up account, the page takes about 35 seconds to load. OK, that's to be expected. But what I did NOT expect was that the partial page updates also take 35 seconds. It's as though all of the savings using partial page rendering have been dissipated.

Is there any reason why a dial-up account has this behaivor and is there anything I can do about it? Thanks for any suggestions.

Ken McLean


hi,

Are you sure you are not doing a complete post back..

Please see if you have set Async="true" in the <%@. Page %> directive of your aspx page.

Thanks

Ruk


Ruk,

Thanks for your quick reply. Yes, I have set Async to "true" in my page directive. It does not seem to make much diffeence whether I include it or not.

I think the delay is caused by a drop-down list on my page which has 2300 entries. When I cut the list to 750, the response time for a partial update was reduced from about 35 seconds to 17 seconds on a dial-up account. If I eliminate the control the response time is cut to a few seconds. It seems that the server is re-loading the complete data for the drop-down control with each partial update. I thought that with AJAX, the data for controls outside the UpDate panels would not have to be re-transmitted but in my case apparently they are. Is there anyway I can stop the drop-down control from being refreshed with each partial update? Thanks for any suggestions.

Ken McLean


Hi Ken,

I have used ajax for partial updates. It has worked for me. If you could post your code I should be able to help you more.


Thanks

Ruk


Ruk,

I wrote a simple test program to demonstrate the problem. It consists of a drop-down list with a lot of dummy data and an AJAX update panel triggered by a button. When the button is clicked, the label inside the Update panel displays the current time. If you replicate this program and run it you will see there is a several second delay before the update panel renders the new time. You can see the amount of time by clicking the button immediatly after a partial update is rendered. Moreover, the delay is proportional to the amount of data in the drop-down list. If you double the number of items in the list the delay for the partial update is also doubled. This implies that the server is retransmitting all of the data for the drop-down list with each partial update. This does not seem consistent with what I have read about AJAX. Is there some setting I am missing that will stop the server from re-transmitting all of the data for the page on a partial update?

Here is the code behind language for the page load event:

ProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.Load
IfNotMe.IsPostBackThen
For jAsInteger = 0To 20000
Me.DropDownList1.Items.Add("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
Next
EndIf
EndSub

Here is the page mark-up:

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:ScriptManagerID="ScriptManager1"runat="server"></asp:ScriptManager>
<asp:DropDownListID="DropDownList1"runat="server">
</asp:DropDownList
<asp:UpdatePanelID="UpdatePanel1"runat="server"UpdateMode="Conditional">
<ContentTemplate>
<asp:LabelID="Label1"runat="server"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTriggerControlID="Button1"EventName="Click"/>
</Triggers>
</asp:UpdatePanel>
<asp:ButtonID="Button1"runat="server"Text="Button"/><br/>
</div>
</form>
</body>
</html>

Thanks for any suggestions.

Ken McLean


When I run the debugger on my site, it runs Page_Load on partial updates. I'm not sure if things outside the updatepanel gets sent back, so if you fill the "dummy data" in another method (not Page_Load), or have the dropdown outside the updatepanel, it might help.


Hi Ken,

You are correct the page does get reloaded. But I think I found the reason for the issue (not the solution :( ). If you check the javascript errors in your browser you will notice that there is an error saying "sys is not defined".

I am using the update panel in another web application. Which I did some time back. But when I run that I didn't get that javascript error. I couldn't figure out why this javascript error is appearing given that your code and what I have done earlier is almost the same.

I'll try again in my free time.

Hope this gives you some idea about the problem.

Thanks

Ruk


Ken, try disabling viewstate temporarily to see if it resolves your performance issues... my guess is that you just have a very large viewstate, and even async postbacks transmit the entire viewstate back and forth.

Ruk, if you're seeing "sys is undefined", check out this blog post by Chris Riccio for some troubleshooting steps:http://weblogs.asp.net/chrisri/archive/2007/02/02/demystifying-sys-is-undefined.aspx.


Thanks Steve..

No comments:

Post a Comment