2
Answers

Enable or disable textboxes based on a check

gerald vince

gerald vince

9y
581
1
I have been trying to get this to work for days, and everything i have read through google shows it should be right, so I have no idea what I am doing wrong, I have a simple checkbox. and once that is checked, i need two other textboxes to become visible or enabled, I dont care which. I am also not stuck on a checkbox, if something is easier I am all for it. 

HTML


<tr>
           <td>
               &nbsp;</td>
           <td style="height: 51px; width: 377px; font-weight: bold;">
               Project Completed?</td>
           <td>
               <asp:CheckBox ID="CheckBox_ProjectResults" OnCheckedChanged="CheckBox_ProjectResults_CheckedChanged" runat="server" Width="200px"></asp:CheckBox>
           </td>
       </tr>
             <tr>
           <td>
               &nbsp;</td>
           <td style="height: 51px; width: 377px; font-weight: bold;">
               End Date</td>
           <td>
               <asp:TextBox ID="TxtActualEnd" runat="server" Width="200px" autocomplete="off"></asp:TextBox>
           </td>
       </tr>
            <tr>
           <td>
               &nbsp;</td>
           <td style="height: 51px; width: 377px; font-weight: bold;">
               Results Folder</td>
           <td>
        <asp:FileUpload ID="attachmentFileUpload" runat="server" Width="320px"/>
       
           </td>
       </tr>




and here is the C# behind it 

protected void CheckBox_ProjectResults_CheckedChanged(object sender, EventArgs e)
        {
            if (CheckBox_ProjectResults.Checked == true)
            {
                TxtActualEnd.Enabled = false;
                attachmentFileUpload.Enabled = false;
            }
            else
            {
                TxtActualEnd.Enabled = true;
                attachmentFileUpload.Enabled = true;
            }
        }


Answers (2)