Enabling/Disabling Form controls with checkbox click.

  • Thread starter Thread starter Assimalyst
  • Start date Start date
A

Assimalyst

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_CheckedChanged);

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.
 
Have you set the AutoPostBack property of the CheckBox to true?
Otherwise it won't post back on checking it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top