title: ASP.NET: Suddenly the name 'form1' does not exist in the current context?
body: <p>This has been working for the past three weeks that I've been developing this application, and for some reason has decided to stop working five minutes ago despite my apparently not doing anything.</p>
  
  <p>In Default.aspx:</p>
  
  <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AppName.Default" %&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html"; charset=utf-8 /&gt;
      &lt;title&gt;&lt;/title&gt;
  
      &lt;script&gt;(A bunch of script declarations, etc)
  
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>In default.aspx.cs:</p>
  
  <pre><code>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);
      }
  }
  </code></pre>
  
  <p>I'm suddenly getting the compiler error 'The name 'form1' does not exist in the current context' despite apparently not having made any changes to either of these files.
  Intellisense can't seem to see it anywhere, from any scope within the file, either.</p>
  
  <p>Does anyone have any idea why?</p>