在过去的三周里,我一直在开发这个应用程序,并且出于某种原因决定在五分钟前停止工作,尽管我显然没有做任何事情。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的' 不当前存在上下文“,尽管显然没有对这些文件做任何修改。 智能感知似乎无法从文件中的任何范围内的任何地方看到它。
有没有人有任何想法为什么?