Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Enable/Disable of texbox

Enable/Disable of texbox

Scheduled Pinned Locked Moved C#
csharpquestion
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    HappyKim
    wrote on last edited by
    #1

    I need to know if my code is right to enable or disable any object in C#.net I use if condition.. is there other way to do it? :(( private void optBCLA01001_SelectedIndexChanged(object sender, System.EventArgs e) { if(optBCLA01001.SelectedIndex == 0) { optBCLA01006.Enabled = true; } }

    D S 2 Replies Last reply
    0
    • H HappyKim

      I need to know if my code is right to enable or disable any object in C#.net I use if condition.. is there other way to do it? :(( private void optBCLA01001_SelectedIndexChanged(object sender, System.EventArgs e) { if(optBCLA01001.SelectedIndex == 0) { optBCLA01006.Enabled = true; } }

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Kind of...It all depends on what a 'optBCLA01006' is. A button?...Checkbox?... For just about all of the usual form controls like buttons and checkboxes and radio buttons, textboxes, ... this is true. BTW: Those variable names are HORRIBLE because they are not descriptive of anything they represent. RageInTheMachine9532 "...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome

      1 Reply Last reply
      0
      • H HappyKim

        I need to know if my code is right to enable or disable any object in C#.net I use if condition.. is there other way to do it? :(( private void optBCLA01001_SelectedIndexChanged(object sender, System.EventArgs e) { if(optBCLA01001.SelectedIndex == 0) { optBCLA01006.Enabled = true; } }

        S Offline
        S Offline
        sreejith ss nair
        wrote on last edited by
        #3

        By default all controls that you are going to place have a Enable property that will allow user to interact with. I think your aim is if the optionbutton is cliecked you ned to enable some control(eg: textbox or label). am i right ? if so. follow like this if(radiobutton1.checked) textboxme.Enabled=false; else textboxme.Enabled=true; here if you click on your radio button it will disable the textbox and if you unchecked it will show the enable the textbox. And on design time you have to deside what is the startup state of your control. Sreejith S S Nair

        H 1 Reply Last reply
        0
        • S sreejith ss nair

          By default all controls that you are going to place have a Enable property that will allow user to interact with. I think your aim is if the optionbutton is cliecked you ned to enable some control(eg: textbox or label). am i right ? if so. follow like this if(radiobutton1.checked) textboxme.Enabled=false; else textboxme.Enabled=true; here if you click on your radio button it will disable the textbox and if you unchecked it will show the enable the textbox. And on design time you have to deside what is the startup state of your control. Sreejith S S Nair

          H Offline
          H Offline
          HappyKim
          wrote on last edited by
          #4

          Thanks... you understand me very well... But could we be more specific: I am using RadioButtonList & textbox. My code is this: private void RadioButtonList1_SelectedIndexChanged(object sender, System.EventArgs e) { if (RadioButtonList1.SelectedIndex ==0) { RadioButtonList2.Enabled=true ; textbox1.Enabled = true; } else { RadioButtonList2.Enabled=false ; textbox1.Enabled = false; } } I am using ASP.NET Web Application, Visual C# Project. The lunching of Internet Explorer is successful without error in build solution and start. My only problem is my code don't do anything. My code will not enable or disable any RadioButtonList or textbox. By the way my default settings of properties in "RadioButtonList2" in my code is disable and I want my code to enable it once the selectedindex is equal to 0 which is the first option of the user. Thanks and more power to you and to this website!!! chiao!!! :)

          S 1 Reply Last reply
          0
          • H HappyKim

            Thanks... you understand me very well... But could we be more specific: I am using RadioButtonList & textbox. My code is this: private void RadioButtonList1_SelectedIndexChanged(object sender, System.EventArgs e) { if (RadioButtonList1.SelectedIndex ==0) { RadioButtonList2.Enabled=true ; textbox1.Enabled = true; } else { RadioButtonList2.Enabled=false ; textbox1.Enabled = false; } } I am using ASP.NET Web Application, Visual C# Project. The lunching of Internet Explorer is successful without error in build solution and start. My only problem is my code don't do anything. My code will not enable or disable any RadioButtonList or textbox. By the way my default settings of properties in "RadioButtonList2" in my code is disable and I want my code to enable it once the selectedindex is equal to 0 which is the first option of the user. Thanks and more power to you and to this website!!! chiao!!! :)

            S Offline
            S Offline
            sreejith ss nair
            wrote on last edited by
            #5

            sorry for this much time.cause i am not feeled well for last two days. ok. now i got your problem. change the AutoPostback property of your first radiolist box control into true.by default it is false. And then try the above mentioned code. have a nice day:-O Sreejith S S Nair

            H 1 Reply Last reply
            0
            • S sreejith ss nair

              sorry for this much time.cause i am not feeled well for last two days. ok. now i got your problem. change the AutoPostback property of your first radiolist box control into true.by default it is false. And then try the above mentioned code. have a nice day:-O Sreejith S S Nair

              H Offline
              H Offline
              HappyKim
              wrote on last edited by
              #6

              Good Day!!! Wonderful.... It works!!! The textbox will enable/disable as I expected!Thank you very much for helping... (Running State)But I jst want to ask if the AutoPostBack will result to refresh effect? I mean each time I change my option to the RadioButtonList the whole web application will download again and will display the new changes made by the user. One more thing!!! How about the coding of CheckBoxList with 4 to 5 choices with corresponding textbox that will also enable each textbox if the choices are being checked. Here is my coding but it wont work as I expected: private void checkboxlist1_SelectedIndexChanged(object sender, System.EventArgs e) { if(checkboxlist1.SelectedIndex == 0) { textbox1.Enabled = true; } if(checkboxlist1.SelectedIndex == 1) { textbox2.Enabled = true; } if(checkboxlist1.SelectedIndex == 2) { textbox3.Enabled = true; } if(checkboxlist1.SelectedIndex == 3) { textbox4.Enabled = true; } } If I checked the first choice it will enable the textbox1 ang when I checked also the second choice the textbox2 will not enable, so on and so on to the other choices. The program will allow me to checked all the choices but will not enable all the corresponding texbox of each choices. Hope you could help me figure out whats wrong with my program.... Thanks and God Bless!!! :-D :doh:

              S 2 Replies Last reply
              0
              • H HappyKim

                Good Day!!! Wonderful.... It works!!! The textbox will enable/disable as I expected!Thank you very much for helping... (Running State)But I jst want to ask if the AutoPostBack will result to refresh effect? I mean each time I change my option to the RadioButtonList the whole web application will download again and will display the new changes made by the user. One more thing!!! How about the coding of CheckBoxList with 4 to 5 choices with corresponding textbox that will also enable each textbox if the choices are being checked. Here is my coding but it wont work as I expected: private void checkboxlist1_SelectedIndexChanged(object sender, System.EventArgs e) { if(checkboxlist1.SelectedIndex == 0) { textbox1.Enabled = true; } if(checkboxlist1.SelectedIndex == 1) { textbox2.Enabled = true; } if(checkboxlist1.SelectedIndex == 2) { textbox3.Enabled = true; } if(checkboxlist1.SelectedIndex == 3) { textbox4.Enabled = true; } } If I checked the first choice it will enable the textbox1 ang when I checked also the second choice the textbox2 will not enable, so on and so on to the other choices. The program will allow me to checked all the choices but will not enable all the corresponding texbox of each choices. Hope you could help me figure out whats wrong with my program.... Thanks and God Bless!!! :-D :doh:

                S Offline
                S Offline
                sreejith ss nair
                wrote on last edited by
                #7

                Sure it will work.Write down your code on valuechange event. and try your all requirement. if you feel any uncomfortable please let me know that.:-O Sreejith S S Nair

                1 Reply Last reply
                0
                • H HappyKim

                  Good Day!!! Wonderful.... It works!!! The textbox will enable/disable as I expected!Thank you very much for helping... (Running State)But I jst want to ask if the AutoPostBack will result to refresh effect? I mean each time I change my option to the RadioButtonList the whole web application will download again and will display the new changes made by the user. One more thing!!! How about the coding of CheckBoxList with 4 to 5 choices with corresponding textbox that will also enable each textbox if the choices are being checked. Here is my coding but it wont work as I expected: private void checkboxlist1_SelectedIndexChanged(object sender, System.EventArgs e) { if(checkboxlist1.SelectedIndex == 0) { textbox1.Enabled = true; } if(checkboxlist1.SelectedIndex == 1) { textbox2.Enabled = true; } if(checkboxlist1.SelectedIndex == 2) { textbox3.Enabled = true; } if(checkboxlist1.SelectedIndex == 3) { textbox4.Enabled = true; } } If I checked the first choice it will enable the textbox1 ang when I checked also the second choice the textbox2 will not enable, so on and so on to the other choices. The program will allow me to checked all the choices but will not enable all the corresponding texbox of each choices. Hope you could help me figure out whats wrong with my program.... Thanks and God Bless!!! :-D :doh:

                  S Offline
                  S Offline
                  sreejith ss nair
                  wrote on last edited by
                  #8

                  don't think like this. if you got a little idea that HOW ? you have to develop the remaining. dear please use little logic and refer MSDN. This forum is for help only not for coding support.ok:-O try this if(CheckBoxList1.SelectedItem.Value.ToString()=="c1") TextBox1.Enabled=false; else TextBox1.Enabled=true; if(CheckBoxList1.SelectedItem.Value.ToString()=="c2") TextBox2.Enabled=false; else TextBox2.Enabled=true; if(CheckBoxList1.SelectedItem.Value.ToString()=="c3") TextBox3.Enabled=false; else TextBox3.Enabled=true; if(CheckBoxList1.SelectedItem.Value.ToString()=="c4") TextBox4.Enabled=false; else TextBox4.Enabled=true; if(CheckBoxList1.SelectedItem.Value.ToString()=="c5") TextBox5.Enabled=false; else TextBox5.Enabled=true; if(CheckBoxList1.SelectedItem.Value.ToString()=="c6") TextBox6.Enabled=false; else TextBox6.Enabled=true; Sreejith S S Nair

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups