Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am trying to use the WebClient Class inside a Visual Web Part (via a User Control code behind class). When I want to run the web part I always get:

Asynchronous operations are not allowed in this context. Page starting an asynchronous operation has to have the Async attribute set to true and an asynchronous operation can only be started on a page prior to PreRenderComplete event.

How can I avoid this. I know that I can set the async property to true on a normal ASP.NET page. But how can I achieve this inside SharePoint 2010.

share|improve this question
add comment

2 Answers 2

At what point in the page lifecycle are you using your WebClient object? Not inside the Render method I hope? :)

If you want to set the Async property of the page, have a look at Page.AsyncMode Property

You should be able to set this.Page.AsyncMode on the Load event (in code-behind) of your Visual WebPart.

share|improve this answer
add comment

I am developing a sharepoint webpart and trying to make async web service calls, I get the "Asynchronous operations are not allowed in this context. Page starting an asynchronous operation..." message. I was trying to add Page.AsyncMode = true; in the OnLoad of the webPart class however my Page doesnt have the AsyncMode property?

any ideas why I dont have the property ?

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.