I've written a custom ASP.NET control and I just updated it to have an async Load event handler. Now I'm getting this error:
An asynchronous operation cannot be started at this time. Asynchronous operations may only be started within an asynchronous handler or module or during certain events in the Page lifecycle. If this exception occurred while executing a Page, ensure that the Page is marked <%@ Page Async="true" %>.
The page does have the <%@ Page Async="true" %>
tag already. So I take it that controls can't have async load event handlers.
Where can I find a comprehensive list of events in the ASP.NET webforms lifecycle that are allowed to be async?
Best Answer
Damian Edwards from the ASP.NET team gave this answer:
Levi Broderick from the ASP.NET team gave this answer:
So I think the answer to my question is: "That's the wrong question."
The right question would be "How should I be async in my ASP.NET Web Forms application?" And the answer is to insert this snippet inside your aspx code-behind file:
This same trick works inside ASP.NET custom controls, just use
this.Page.RegisterAsyncTask
instead.