0

I have a typical RadAjaxLoadingPanel that fires when a button click method calls a Response.Redirect. The redirect page has several expensive stored procedures in the OnLoad method. This seems to lock up the UI, and the circle freezes until those stored procedures finish. Should those stored procedures remain in the OnLoad method? Is there a better implementation when loading a Response.Redirect that prevents a UI lockup?

protected void Button_Click(object sender, EventArgs e)
{
    Response.Redirect("~/page.aspx", false);
}
snippetkid
  • 282
  • 4
  • 16
fix
  • 1,425
  • 16
  • 27
  • Unless I'm misunderstanding your question, all three of the events in your title need to complete before the page is fully rendered. Maybe you need an ajax panel on the destination page that will load the data asynchronously so that you at least can show a "data loading..." message or something other than the Spinning Wheel of Death? – D Stanley Jan 20 '16 at 15:17
  • 1
    How expensive is "expensive"? Generally if something takes more than a few seconds, it should be a [background task](http://www.hanselman.com/blog/HowToRunBackgroundTasksInASPNET.aspx). – mason Jan 20 '16 at 15:30
  • @mason I was going to say the exactly same thing. fix - Background task/scheduler could be a good option if you want to run a long running process without freezing the UI. – Win Jan 20 '16 at 15:33
  • @Mason Expensive as in sometimes 20-40 seconds given how well the VPN is working that day. – fix Jan 20 '16 at 15:40
  • Yeah, better to background that. The user should make a web request that kicks off the background process. The user can be notified their request has been accepted. Depending on the scenario you can either just wait for them to refresh the page, or you can monitor the background task and keep the user informed of the status (using AJAX, web sockets, or perhaps [SignalR](http://signalr.net/)). – mason Jan 20 '16 at 15:43
  • @Win I did try the BackgroundWorker for the stored procedure, but it still locked up the UI until it completed. – fix Jan 20 '16 at 15:55
  • 1
    We're working with a limited understanding of your entire application, so it's hard to know how to suggest the best fix. But if the page requires data from these stored procs, it won't really matter if the calls to them are in OnInit, OnLoad or OnPreRender. Some options: First, Have you tried to optimize and tune the queries? Have you properly indexed the tables? Any query that takes this long to run smells bad. Second, is it possible to cache the data somehow so that you don't have to go to the DB every time the page loads? – Casey Crookston Jan 20 '16 at 16:06
  • @CaseyCrookston 1. The indexing and query are out of my hands, unfortunately. I am applying a bandaid to an unavoidable long query. I admit that the client database architecture is not great, but it's out of my control and under strict control. 2. I do cache the data after the initial query during OnLoad, but the initial query is where the UI freezes. – fix Jan 20 '16 at 17:00

1 Answers1

0

Do this. Run the stored procedure through Management Studio or any designer program you're using to connect to your database. How long does this operation take?

Now navigate to your program setup a background process to take care of stored procedure work - but in your function that is calling the stored procedure make sure there is a return line:

return [something];

Maybe you're wanting the function or method to return a list or a value? You must return something back to the view while the stored procedure is running so that your process isn't being held up.

Compare the execution time of the operation in your program versus the one directly from your database. It seems to me that regardless of how long your stored procedure takes if it's needed in the view having it initialize in the OnInit, OnLoad or OnPreRender won't matter.

Faraji Anderson
  • 653
  • 6
  • 18