title: Enabling a Textbox using a checkbox in ASP.NET?
body: <p>We have tried to link the checkBox1 to txtCommentBox using C#. We are trying to make it so that the txtCommentBox stays disabled until the checkBox1 is checked.</p>
  
  <p>We've done the below.</p>
  
  <pre><code>if (checkBox1.Enabled)
  {
      txtCommentBox.Enabled = true;
  }
  </code></pre>
  
  <p>After that failed, we then in the page_Load method, we've tried to do the below.</p>
  
  <pre><code>txtCommentBox.Enabled = checkBox1.Enabled;
  </code></pre>
  
  <p>That didn't work either. We've tried various properties with the controls with no luck.
  The .aspx code is below, with the C# code further below.</p>
  
  <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="Infomation.aspx.cs" Inherits="Infomation" %&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 xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;
      &lt;title&gt;Information&lt;/title&gt;
      &lt;link href="StyleSheet.css" rel="stylesheet" type="text/css" /&gt;
      &lt;style type="text/css"&gt;
          .style1
          {
              width: 100%;
          }
          .style2
          {
              width: 605px;
          }
      &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
      &lt;div&gt;
  
          &lt;h4&gt;
              If you would like to leave your Questions, Comments, E-mail, Name or Phone 
              Number check off the box you would like to enter into the form.
          &lt;/h4&gt;
  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
          &lt;table class="style1"&gt;
              &lt;tr&gt;
                  &lt;td class="style2"&gt;
                      &lt;asp:Label ID="Label1" runat="server"&gt;&lt;span class="accesskey"&gt;C&lt;/span&gt;omment:&lt;/asp:Label&gt;
  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
                      &lt;asp:TextBox ID="txtCommentBox" runat="server" AccessKey="C" Width="334px" 
                          ontextchanged="txtCommentBox_TextChanged" Enabled="False"&gt;&lt;/asp:TextBox&gt;
                      &lt;asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack = "true"
                          oncheckedchanged="CheckBox1_CheckedChanged" Text="Enable/disable" /&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &amp;nbsp;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td class="style2"&gt;
                      &lt;asp:Label ID="Label2" runat="server"&gt;&lt;span class="accesskey"&gt;E&lt;/span&gt;mail:&lt;/asp:Label&gt;
  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
                      &lt;asp:TextBox ID="txtEmailBox" runat="server" AccessKey="E" Width="334px" 
                          ontextchanged="txtEmailBox_TextChanged" Enabled="False"&gt;&lt;/asp:TextBox&gt;
                      &lt;asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack = "true"
                          oncheckedchanged="CheckBox2_CheckedChanged" Text="Enable/disable" /&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &amp;nbsp;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td class="style2"&gt;
                      &lt;asp:Label ID="Label3" runat="server"&gt;&lt;span class="accesskey"&gt;N&lt;/span&gt;ame:&lt;/asp:Label&gt;
  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
                      &lt;asp:TextBox ID="txtNameBox" runat="server" AccessKey="N" Width="334px" 
                          ontextchanged="txtNameBox_TextChanged" Enabled="False"&gt;&lt;/asp:TextBox&gt;
                      &lt;asp:CheckBox ID="CheckBox3" runat="server" AutoPostBack = "true"
                          oncheckedchanged="CheckBox3_CheckedChanged" Text="Enable/disable" /&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &amp;nbsp;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td class="style2"&gt;
                      &lt;asp:Label ID="Label4" runat="server"&gt;&lt;span class="accesskey"&gt;P&lt;/span&gt;hone Number:&lt;/asp:Label&gt;
                      &lt;asp:TextBox ID="txtPhoneBox" runat="server" AccessKey="P" Width="334px" 
                          ontextchanged="txtPhoneBox_TextChanged" Enabled="False"&gt;&lt;/asp:TextBox&gt;
                      &lt;asp:CheckBox ID="CheckBox4" runat="server" AutoPostBack = "true"
                          oncheckedchanged="CheckBox4_CheckedChanged" Text="Enable/disable" /&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &amp;nbsp;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
          &lt;asp:ListBox ID="ListBox1" runat="server" Height="321px" Width="887px"&gt;
          &lt;/asp:ListBox&gt;
          &lt;br /&gt;
          &lt;br /&gt;
          &lt;br /&gt;
          &lt;br /&gt;
  
          &lt;br /&gt;
          &lt;br /&gt;
          &lt;asp:Button ID="Button1" runat="server" onclick="Button1_Click" 
              Text="Back to the Main Page" /&gt;
          &lt;br /&gt;
  
      &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I've put our C# code for what where we're at, below:</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 Infomation : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e)
      {
          if (!IsPostBack)
          {
              txtCommentBox.Enabled = false;
              txtEmailBox.Enabled = false;
              txtNameBox.Enabled = false;
              txtPhoneBox.Enabled = false;
          }
      }
      protected void Button1_Click(object sender, EventArgs e)
      {
          Response.Redirect("JoelsDefaultPage.aspx");
      }
      protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
      {
          if (CheckBox1.Enabled == true)
              txtCommentBox.Enabled = true;
          else
              txtCommentBox.Enabled = false;
      }
      protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
      {
          if (CheckBox2.Enabled == true)
              txtEmailBox.Enabled = true;
          else
              txtEmailBox.Enabled = false;
      }
      protected void CheckBox3_CheckedChanged(object sender, EventArgs e)
      {
          if (CheckBox3.Enabled == true)
              txtNameBox.Enabled = true;
          else
              txtNameBox.Enabled = false;
      }
      protected void CheckBox4_CheckedChanged(object sender, EventArgs e)
      {
          if (CheckBox4.Enabled == true)
              txtPhoneBox.Enabled = true;
          else
              txtPhoneBox.Enabled = false;
      }
      protected void txtCommentBox_TextChanged(object sender, EventArgs e)
      {
  
      }
      protected void txtEmailBox_TextChanged(object sender, EventArgs e)
      {
  
      }
      protected void txtNameBox_TextChanged(object sender, EventArgs e)
      {
  
      }
      protected void txtPhoneBox_TextChanged(object sender, EventArgs e)
      {
  
      }
  }
  </code></pre>
  
  <p><strong>EDIT #1</strong></p>
  
  <p>Okay, so the AutoPostBack sort of worked. I can now enable the textbox from its disabled state, however I cannot disable it again.</p>
  
  <p><strong>UPDATE #1</strong></p>
  
  <p>I've updated the code to what we have now.</p>