Should stored procedures be called in OnInit, OnLoad, or OnPreRender?

212 views Asked by At

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);
}
1

There are 1 answers

0
Faraji Anderson On

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.