简体   繁体   中英

How to place Async=“true” on masterpage

In my master page I will load some data from the database. I have place it into an asynchronous method. For normal pages I place Async="true" on the top but if I do it on the master page, I have the following error:

myproject.master does not contain a definition for AsyncMode and blablabla...

I've also search on the internet but nothing found for an asynchronous master page. Language I use on background is C#.

Can anyone help me?

You can set it in the master page like this. Found solution here:

public abstract class MyBasePage : System.Web.UI.Page
{
    public MyBasePage()
    {
        this.AsyncMode = true;
    }
}

Then change the inheritance in the aspx.cs file to something like this:

public partial class WebForm1 : MyBasePage

It can break the system when you set the AsyncMode property in anything else then the constructor.

The sample uses the new async and await keywords (available in .NET 4.5 and Visual Studio 2012) to let the compiler be responsible for maintaining the complicated transformations necessary for asynchronous programming . The compiler lets you write code using the C#'s synchronous control flow constructs and the compiler automatically applies the transformations necessary to use callbacks in order to avoid blocking threads. ASP.NET asynchronous pages must include the Page directive with the Async attribute set to "true".

Master File contain master directive.

Master Page inherit MasterPage class of System.Web.UI which does not contain AsyncMode property..So you can't use it at master page .

Normal Page inherit Page class of System.Web.UI which contain AsyncMode .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM