Regarding Enabling And disabling Textbox values

asp.net Hong Kong SAR
  • 12 years ago

    Hi All,

      I want to enable my text box to enter values in it, if the check box is checked..

      If the check box is not checked , Then it should not allow the text box to enter values...

    I have tried like this,

    if(checkbox1.checked==true)

        textbox1.enabled=true;

    By default checkbox checked is false and text enabled is false..

     

    But it is not working in my coding......

     

    Anyone knows wat m doing wrong, tell me..

    Thanks in advance


     

  • 12 years ago

    hi,flower123 ,

            you should write the code in the event of checkBox1_CheckStateChanged,as follows

             private void checkBox1_CheckStateChanged(object sender, System.EventArgs e)
            {
               if(checkBox1.Checked)
                {
                    textBox1.Enabled=true;
                }
               else
                {
                 textBox1.Enabled=false;
                }
           }

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone” - Bjarne Stroustrup