![](/img/trans.png)
[英]How do I solve the error 'System.Web.UI.MasterPage' does not contain a definition for
[英]“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.