Click here to Skip to main content
15,920,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a requirement in my project which is being developed in C#.
I would like to enable/disable one asp.textbox based on the checking/Unchecking ASP:Checkbox.

Kindly let me know how to implement it (best way)?

Updated 24-Jan-12 8:41am

You can either do it using javascript, or you can use the onCheckChanged event on the checkbox and then handle the disabling of the textbox in the code-behind. I won't just give you the code for this as it is a very basic thing. Try it out and if you run into coding issues, update your question and we can help further.
Share this answer
Espen Harlinn 24-Jan-12 15:58pm    
fjdiewornncalwe 24-Jan-12 16:49pm    
Thank you, Espen.
Sergey Alexandrovich Kryukov 24-Jan-12 23:57pm    
Agree, my 5. I only covered client-side variant. Teamwork!
fjdiewornncalwe 25-Jan-12 8:39am    
Thanks, Sergei
Tech Code Freak 25-Jan-12 2:30am    
I thing, the best way would be doing it on the client side only (it this is acceptable; some sites are required to perform even it the user switched scripting off in the browser), because the postback for this simple operation would might take to much time to be reasonable. That said, you could do it in JavaScript; and one convenient way of doing it would be using jQuery.

To enable/disable, you can use this:

$('#myTextBoxId').attr('disabled', '');

You can handle the click event of the text, check if it is checked and enable or disable the text box accordingly:

$('#myCheckBox').click (function () {
    var thisCheck = $(this);
    if ( (':checked')) {
        //enable text box here, see the code fragment above
    } else {
        //disable text box here, see the code fragment above

Something like that.

Please see:[^],[^] (see how to work with attributes),[^] (working with "checked").

Share this answer
Espen Harlinn 24-Jan-12 15:57pm    
Good reply :)
Sergey Alexandrovich Kryukov 24-Jan-12 16:28pm    
Thank you, Espen.
fjdiewornncalwe 24-Jan-12 16:49pm    
Nice. I didn't want to give the OP something this complete, but I do like the answer. +5.
Sergey Alexandrovich Kryukov 24-Jan-12 16:51pm    
Thank you, Marcus.
Actually I've just done what I though was fastest for me to show in the answer.
Tech Code Freak 25-Jan-12 2:30am    

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900