2010-10-21 31 views
0

在過去的三週裏,我一直在開發這個應用程序,並且出於某種原因決定在五分鐘前停止工作,儘管我顯然沒有做任何事情。ASP.NET:突然在當前上下文中不存在名稱'form1'?

Default.aspx中:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AppName.Default" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html"; charset=utf-8 /> 
    <title></title> 

    <script>(A bunch of script declarations, etc) 

</head> 
<body> 
    <form id="form1" runat="server"> 
    </form> 
</body> 
</html> 

在default.aspx.cs:

public partial class Default : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     System.Web.UI.HtmlControls.HtmlGenericControl g = new System.Web.UI.HtmlControls.HtmlGenericControl(); 

     //(Dynamically builds a load of html to insert into the form) 

     form1.Controls.Add(g); 
    } 
} 

我突然收到編譯器錯誤「名稱 'form1的' 不當前存在上下文「,儘管顯然沒有對這些文件做任何修改。 智能感知似乎無法從文件中的任何範圍內的任何地方看到它。

有沒有人有任何想法爲什麼?

回答

0

頭部聲明中沒有runat =「Server」的問題,我必須在兩週前更改它,直到今天儘管幾次完整重建項目,Visual Studio仍然設法不會出現問題。典型的微軟。

1

檢查Form1中存在於設計文件(default.aspx.designer.cs),因爲我懷疑其失蹤

1

在VS生成菜單,嘗試運行「清理解決方案」,然後建立。

相關問題