繁体   English   中英

“System.Web.UI.MasterPage不包含定义...”ASP.NET错误

[英]“System.Web.UI.MasterPage does not contain a definition…” ASP.NET error

编辑:主要问题似乎是我只是从旧网站项目“添加现有项目”到ASP.NET Web应用程序项目。 这引起了很多麻烦我只是从头开始,除了不是添加现有项目,我添加了新的母版页和aspx页面,然后填充它们。 同样的问题仍然存在。

我有一个遗留项目,它只是一个标准的网站。 我已经开始了一个新项目作为Web应用程序,并已移植到我需要的所有页面中。 但是,我收到了100多个错误,这些错误主要包含以下几种略有不同的排列:

  • 'System.Web.UI.MasterPage does not contain a definition for 'headerImage' (我在代码隐藏中得到这个)
  • 'MasterPage' does not contain a definition for '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基类中寻找这个属性!

我已经查看了这篇文章,但它并没有解决我的问题。

思考? 所有反馈都表示赞赏。 多谢你们。

早上好,当你将现有文件添加到新的Web应用程序时,你是从头开始重新创建它们还是做了文字“添加现有项目”? 如果是这样,那么您应该右键单击每个文件,然后单击“转换为Web应用程序”选项。

检查this.Master的命名空间是什么。 如果是System.Web.UI.MasterPage ,请尝试将主页重命名为其他名称。 这样您就可以隔离问题。

我的答案与@mreyeros类似 - 但是,我的设计师文件已经存在 - 这是Vs无法识别非设计者类的部分性质,因此将2连接在一起。

我使用的修复是从项目中删除文件并使用add existing重新添加它们。 我是批量做的,新添加的文件表现正常,错误消失了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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