在過去的三週裏,我一直在開發這個應用程序,並且出於某種原因決定在五分鐘前停止工作,儘管我顯然沒有做任何事情。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的' 不當前存在上下文「,儘管顯然沒有對這些文件做任何修改。 智能感知似乎無法從文件中的任何範圍內的任何地方看到它。
有沒有人有任何想法爲什麼?