title: Session Variable - The name does not exist in current context
body: <p>I keep getting the error "The name "User Name" does not exist in the current context. As you can see "UserName" is clearly defined on my code behind page and I am referencing my page. So why does it say that it does not exist?</p>
  
  <p>Here is my C# -</p>
  
  <pre><code>public partial class Account_Login : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e)
      {}
  
      protected void btnLogOn_Click(object sender, EventArgs e)
      {
          Session["SubName"] = UserName.Text;
      }
  }
  </code></pre>
  
  <p>Here is my HTML - </p>
  
  <pre><code>&lt;p&gt;
          Please enter your username and password.
      &lt;/p&gt;
  
      &lt;form action="/Account/LogOn" method="post"&gt;
          &lt;div&gt;
              &lt;fieldset&gt;
                  &lt;legend&gt;Account Information&lt;/legend&gt;
  
                  &lt;div class="editor-label"&gt;
                      &lt;label for="UserName"&gt;User name&lt;/label&gt;
                  &lt;/div&gt;
                  &lt;div class="editor-field"&gt;
                      &lt;input id="UserName" name="UserName" type="text" value="" /&gt;
  
                  &lt;/div&gt;
  
                  &lt;div class="editor-label"&gt;
                      &lt;label for="Password"&gt;Password&lt;/label&gt;
                  &lt;/div&gt;
                  &lt;div class="editor-field"&gt;
                      &lt;input id="Password" name="Password" type="password" /&gt;
  
                  &lt;/div&gt;
  
                  &lt;p&gt;
                      &lt;input id="btnLogOn" type="submit" value="Log On" /&gt;
                  &lt;/p&gt;
              &lt;/fieldset&gt;
          &lt;/div&gt;
      &lt;/form&gt;
          &lt;/div&gt; 
  </code></pre>