Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Page Async mode to true from Code-Behind

Is it possible within my code-behind file to set the asynchronous mode of the page directive.

I have no way of directly modifying the <%@Page %> attribute and and struggling to find a way to implement this in my code-behind.

I have tried in my Page_Load method to add Page.AsyncMode = true, but it returns the following error:

is inaccessible due to its protection level

Is there any way to do this? Without being able to directly modify the master page?

like image 941
ScampDoodle Avatar asked Sep 01 '25 18:09

ScampDoodle


1 Answers

No, you cannot change the asynchronous mode of a page in the code-behind. An asynchronous page implements the IHttpAsyncHandler interface, and there is no way to change the interfaces implemented by your page after the .aspx file has been compiled by ASP.NET and your code is running.

Setting the Page.AsyncMode property will not change the asynchronous mode. Its purpose is to let controls on the page know whether the page is running in asynchronous mode or not, so tampering with the property may cause controls to malfunction.

like image 183
Michael Liu Avatar answered Sep 04 '25 06:09

Michael Liu