在我的 ASP.Net Web 应用程序中,我有一个基页面,它实现了跨 Web 应用程序所有页面的功能,并且我的网页派生自该基页面。
由于整个网站只有一个母版页,因此我不想在每个网页中附加母版页。因此,我通过基本页的 OnPreInit 方法附加了母版页,如下所示:
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.
当我运行该应用程序时,网页会正确显示。
应该怎么做才能使设计器正确显示而不必在每个网页中显式设置母版页?
顺便说一句,我使用的是 Visual Studio 2010 和 .Net 4.0
你很幸运,你可以在你的网络配置,并且它将显示在设计器中,而无需在页面上显式设置。我刚刚测试了一下。只需查找下面的行并放入您的母版页文件即可。
<pages masterPageFile="~/MasterPage.master">
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)