C# ASP.NET Slow AJAX loading

When I call a page with AJAX, everything goes fast and well. But if I have a page (for testing purposes) with the following code:

for(int i = 0; i < int.MaxValue; i++)

the page loading is longer, which is obvious. But then, when I load a page that only sets a text on a label, it takes longer (about 5 seconds), but this ain't the case if I call this page before calling the test page (with the for loop).

So, all the loading goes fast, except when I call the test page. From there on every page loads slow. How come?

13.10.2009 14:12:31

If that for...next loop is in the pageload of your page, ALL ajax queries will have to run that same loop; you should put any long-running processes inside a this.IsPostPack == false if statement, and then persist that data in viewstate if you need it during subsequent postbacks.

13.10.2009 14:20:35
Yes, the for loop is in the page_load event of the test page. But I don't want this data to be saved in the ViewState. I cannot set the if(!isPostBackData) because than the code isn't executed.
Martijn 13.10.2009 14:27:50

I found the solution. It was bad programming. With AJAX I was loading Web User Controls (ascx files). I saved the controls in the ViewState and in my page load I loaded these controls again. So per page load the previous user control was loaded. By removing this method in the page_load my problem is solved.

Thanks for the effort though.

13.10.2009 14:55:49