![]() |
|
|
|||||||
![]() |
ASP Net - Enabling/Disabling Form controls with checkbox click. |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
Hi I am attempting to enable/disable webform controls depending on
whether a checkbox is checked or not. I have an event handler for when the checkbox checked is changed this.addNewSurgeonChkBx.CheckedChanged += new System.EventHandler(this.addNewSurgeonChkBx_Checke dChanged); And the code called by this is: private void addNewSurgeonChkBx_CheckedChanged(object sender, System.EventArgs e) { if (addNewSurgeonChkBx.Checked == true) { titleCboBx.Enabled = true; fNameTxtBx.Enabled = true; lNameTxtBx.Enabled = true; surgeonNameCboBx.Enabled = false; } else { titleCboBx.Enabled = false; fNameTxtBx.Enabled = false; lNameTxtBx.Enabled = false; surgeonNameCboBx.Enabled = true; } } But when I load the page and check the checkbox nothing happens, the disabled controls remain disabled, the enabled ones remain enabled. Any ideas why? Thanks. Assimalyst |
|
|
|
|
#2 |
|
Posts: n/a
|
Hi Assimalyst
perhaps you need to set autopost back property of checkbox to true. Also you can cut short your long statements by following lines, if your routine is just intend to implement toggle. titleCboBx.Enabled = !titleCboBx.Enabled fNameTxtBx.Enabled = !fNameTxtBx.Enabled Regards Jignesh Desai - MVP Blogs @ http://dotnetjini.jigneshdesai.com/Blogs/default.aspx ..NET Training Programs : http://dotnetjini.jigneshdesai.com/Training.aspx "Assimalyst" <> wrote in message news: ups.com... > Hi I am attempting to enable/disable webform controls depending on > whether a checkbox is checked or not. > > I have an event handler for when the checkbox checked is changed > > this.addNewSurgeonChkBx.CheckedChanged += new > System.EventHandler(this.addNewSurgeonChkBx_Checke dChanged); > > And the code called by this is: > > private void addNewSurgeonChkBx_CheckedChanged(object sender, > System.EventArgs e) > { > if (addNewSurgeonChkBx.Checked == true) > { > titleCboBx.Enabled = true; > fNameTxtBx.Enabled = true; > lNameTxtBx.Enabled = true; > surgeonNameCboBx.Enabled = false; > } > else > { > titleCboBx.Enabled = false; > fNameTxtBx.Enabled = false; > lNameTxtBx.Enabled = false; > surgeonNameCboBx.Enabled = true; > } > } > > But when I load the page and check the checkbox nothing happens, the > disabled controls remain disabled, the enabled ones remain enabled. Any > ideas why? > > Thanks. > Jignesh Desai |
|
|
|
#3 |
|
Posts: n/a
|
Have you set the AutoPostBack property of the CheckBox to true?
Otherwise it won't post back on checking it. "Assimalyst" <> wrote in message news: ups.com... > Hi I am attempting to enable/disable webform controls depending on > whether a checkbox is checked or not. > > I have an event handler for when the checkbox checked is changed > > this.addNewSurgeonChkBx.CheckedChanged += new > System.EventHandler(this.addNewSurgeonChkBx_Checke dChanged); > > And the code called by this is: > > private void addNewSurgeonChkBx_CheckedChanged(object sender, > System.EventArgs e) > { > if (addNewSurgeonChkBx.Checked == true) > { > titleCboBx.Enabled = true; > fNameTxtBx.Enabled = true; > lNameTxtBx.Enabled = true; > surgeonNameCboBx.Enabled = false; > } > else > { > titleCboBx.Enabled = false; > fNameTxtBx.Enabled = false; > lNameTxtBx.Enabled = false; > surgeonNameCboBx.Enabled = true; > } > } > > But when I load the page and check the checkbox nothing happens, the > disabled controls remain disabled, the enabled ones remain enabled. Any > ideas why? > > Thanks. > Grant Merwitz |
|
|
|
#4 |
|
Posts: n/a
|
Thankyou both, problem solved.
Assimalyst |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to activate Remote Assistance with XP using Windows Live Messenger | Oziisr | General Help Related Topics | 0 | 02-01-2008 04:45 PM |
| How to make your wonderful photo and video slideshow on DVD | kricww@gmail.com | DVD Video | 0 | 04-20-2006 07:26 AM |
| Converting PAL DVDs to NTSC DVDs. | Wild Coyote | DVD Video | 14 | 10-27-2004 09:58 PM |
| winsock.dll | J | A+ Certification | 7 | 07-20-2004 01:01 AM |
| Latest Tech Fiasco... | Ghost | A+ Certification | 30 | 01-09-2004 12:15 PM |