title: Code Behind file doesn't recognize control names despite them existing in the designer page
body: <p>My computer died over the weekend, and my backups failed. I was building an ASP.NET C# site, so naturally all the files are gone. I re-downloaded Visual Studio as well as all my site files from the web server. The only things that didn't make it were the <code>.designer.cs files.</code> This is where the problems come in. Not a single one of my code behind pages recognizes the control names on its parent page. </p>
  
  <ul>
  <li><p>StackOverflow told me to run <code>Project &gt; Convert to Web Application</code>,
  so I did. This added a designer page, but didn't solve the problem.</p></li>
  <li><p>If I try to add a new control and access its click event, VS puts the
  code inside a <code>&lt;script&gt;</code> tag on the parent page, not in the code
  behind.</p></li>
  <li><p>All the control names are correct and present on the new designer page.</p></li>
  </ul>
  
  <p>I have no idea whatsoever why these pages aren't connecting to each other. Below is my code for one of the pages. They're all similar to this one. Thank you so much for any help.</p>
  
  <p>Code for parent page:</p>
  
  <pre><code>&lt;%@ Page Title ="Calculator Demo" Language ="C#" AutoEventWireup="True"
      Inherits="CalculatorDemo.aspx.cs" Codebehind="CalculatorDemo.aspx.cs" %&gt;
  
  &lt;!DOCTYPE html&gt;
  &lt;script runat="server"&gt;  
  &lt;/script&gt;    
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;
      &lt;title&gt;&lt;/title&gt;
      &lt;style type="text/css"&gt;
          .auto-style1 {
              width: 100%;
          }
      &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
          &lt;div&gt;
              &lt;table class="auto-style1"&gt;
                  &lt;tr&gt;
                      &lt;td colspan="3"&gt;
                          &lt;asp:Label ID="lblResultLabel" runat="server"&gt;&lt;/asp:Label&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;
                          &lt;asp:TextBox ID="txtValueBox1" runat="server"
                              OnTextChanged="txtValueBox1_TextChanged"&gt;
                          &lt;/asp:TextBox&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;asp:DropDownList ID="ddlOperatorList" runat="server"&gt;
                              &lt;asp:ListItem&gt;+&lt;/asp:ListItem&gt;
                              &lt;asp:ListItem&gt;-&lt;/asp:ListItem&gt;
                              &lt;asp:ListItem&gt;*&lt;/asp:ListItem&gt;
                              &lt;asp:ListItem&gt;/&lt;/asp:ListItem&gt;
                          &lt;/asp:DropDownList&gt;
                          &lt;asp:TextBox ID="txtValueBox2" runat="server"&gt;
                          &lt;/asp:TextBox&gt;
                      &lt;/td&gt;
                      &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                      &lt;td&gt;
                          &lt;asp:Button ID="btnCalculate" runat="server" 
                              OnClick="btnCalculate_Click" Text="Calculate" /&gt;
                      &lt;/td&gt;
                      &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
          &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Code for Code Behind:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  
  public partial class Demos_CalculatorDemo : BasePage
  {       
      protected void btnCalculate_Click(object sender, EventArgs e)
      {
          if (txtValueBox1.Text.Length &gt; 0 &amp;&amp; txtValueBox2.Text.Length &gt; 0)
          {
              double result = 0;
              double value1 = Convert.ToDouble(txtValueBox1.Text);
              double value2 = Convert.ToDouble(txtValueBox2.Text);
  
              Calculator myCalculator = new Calculator();
  
              switch (ddlOperatorList.SelectedValue)
              {
                  case "+":
                      result = myCalculator.Add(value1, value2);
                      break;
                  case "-":
                      result = myCalculator.Subtract(value1, value2);
                      break;
                  case "*":
                      result = myCalculator.Multiply(value1, value2);
                      break;
                  case "/":
                      result = myCalculator.Divide(value1, value2);
                      break;
              }
  
              lblResultLabel.Text = result.ToString();
          }
          else
          {
              lblResultLabel.Text = string.Empty;
          }
      }
  }
  </code></pre>
  
  <p>Code for designer page:</p>
  
  <pre><code>//------------------------------------------------------------------------------
  // &lt;auto-generated&gt;
  //     This code was generated by a tool.
  //
  //     Changes to this file may cause incorrect behavior and will be lost if
  //     the code is regenerated. 
  // &lt;/auto-generated&gt;
  //------------------------------------------------------------------------------
  
  namespace CalculatorDemo.aspx
  {       
      public partial class cs
      {    
          /// &lt;summary&gt;
          /// form1 control.
          /// &lt;/summary&gt;
          /// &lt;remarks&gt;
          /// Auto-generated field.
          /// To modify move field declaration from designer file to code-behind file.
          /// &lt;/remarks&gt;
          protected global::System.Web.UI.HtmlControls.HtmlForm form1;
  
          /// &lt;summary&gt;
          /// lblResultLabel control.
          /// &lt;/summary&gt;
          /// &lt;remarks&gt;
          /// Auto-generated field.
          /// To modify move field declaration from designer file to code-behind file.
          /// &lt;/remarks&gt;
          protected global::System.Web.UI.WebControls.Label lblResultLabel;
  
          /// &lt;summary&gt;
          /// txtValueBox1 control.
          /// &lt;/summary&gt;
          /// &lt;remarks&gt;
          /// Auto-generated field.
          /// To modify move field declaration from designer file to code-behind file.
          /// &lt;/remarks&gt;
          protected global::System.Web.UI.WebControls.TextBox txtValueBox1;
  
          /// &lt;summary&gt;
          /// ddlOperatorList control.
          /// &lt;/summary&gt;
          /// &lt;remarks&gt;
          /// Auto-generated field.
          /// To modify move field declaration from designer file to code-behind file.
          /// &lt;/remarks&gt;
          protected global::System.Web.UI.WebControls.DropDownList ddlOperatorList;
  
          /// &lt;summary&gt;
          /// txtValueBox2 control.
          /// &lt;/summary&gt;
          /// &lt;remarks&gt;
          /// Auto-generated field.
          /// To modify move field declaration from designer file to code-behind file.
          /// &lt;/remarks&gt;
          protected global::System.Web.UI.WebControls.TextBox txtValueBox2;
  
          /// &lt;summary&gt;
          /// btnCalculate control.
          /// &lt;/summary&gt;
          /// &lt;remarks&gt;
          /// Auto-generated field.
          /// To modify move field declaration from designer file to code-behind file.
          /// &lt;/remarks&gt;
          protected global::System.Web.UI.WebControls.Button btnCalculate;
      }
  }
  </code></pre>