编辑:主要问题似乎是我只是将旧网站项目中的“添加现有项目”添加到 ASP.NET Web 应用程序项目中。这给我带来了很多麻烦,我只是从头开始,只是我没有添加现有项目,而是向项目添加了新的母版页和 aspx 页面,然后填充它们。同样的问题仍然存在。
我有一个遗留项目,它只是一个标准网站。我已经启动了一个新项目作为 Web 应用程序,并移植了我需要的所有页面。但是,我收到了 100 多个错误,这些错误主要由以下各项略有不同的排列组成:
'System.Web.UI.MasterPage 不包含 'headerImage' 的定义
(我在代码隐藏中得到它)“MasterPage”不包含“imgHeader”的定义
(这也在代码隐藏中)
关于第一个错误,就好像项目没有理解母版页的设置。我将母版页设置在每个 aspx 页面的顶部,例如:
<%@ page language="C#" masterpagefile="~/MasterPages/MasterPage.master" autoeventwireup="true" inherits="Equipment.aspx.cs" title="Untitled Page" %>
<%@ MasterType VirtualPath="~/MasterPages/MasterPage.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<!-- some content -->
</asp:Content>
此外,我清楚地在 ~/MasterPages/MasterPage.master 代码隐藏中公开了一个 headerImage
属性:
public partial class MasterPage : System.Web.UI.MasterPage
{
#region Properties
private string _headerImage;
public string headerImage
{
get
{
return _headerImage;
}
set
{
_headerImage = (string)value;
}
}
// other stuff
}
然而 VS 仍在 System.Web.UI.MasterPage 基类中寻找这个属性!
我已经 checkout this发布,但它没有解决我的问题。
想法?感谢所有反馈。谢谢大家。
最佳答案
早上好,当您将现有文件添加到新的 Web 应用程序时,您是从头开始重新创建它们还是直接执行“添加现有项目”?如果是这样,那么您应该右键单击每个文件并单击“转换为 Web 应用程序”选项。
关于c# - "System.Web.UI.MasterPage does not contain a definition..."ASP.NET 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9278365/