How to work with Master Page that is attached to the page via the page's basepage?
In my ASP.Net web application, I have a base page that implements functionality that spans all pages of the web application and my web pages derive from this base page.
Since there is a single master page for the entire website, I don't want to attach the master page in each of the web pages. So I attached the Master page via the basepage's OnPreInit method as follows:
protected override void OnPreInit(EventArgs e)
{
this.MasterPageFile = "~/Site.master";
base.OnPreInit(e);
}
However, when I switch to Designer view, I get the "Master Page Error"; The page has controls that require a Master Page reference, but noe is specified. Correct the problem in Code View.
When I run the application, the webpage shows up correctly.
What should be done so that the designer shows up correctly without having to go and set the master page explicitly in each of the web pages?
BTW, I am on Visual Studio 开发者_运维知识库2010 and .Net 4.0
You are in luck you can set the masterpage file in your web.config, and it will show in the designer without being explicitly set on the page. I just tested it out. Just look for the line below and put in your master page file.
<pages masterPageFile="~/MasterPage.master">
精彩评论