I’m trying to disable a label control from the CheckedChanged event handler of a checkbox. Should I be able to do this?
At the moment if I set Enabled to false nothing changes when the page reloads. If I do the same thing in Page_Load then I see the change.
To clarify:
This doesn’t work:
protected void chkNeverExpires_CheckedChanged(object sender, EventArgs e) { this.lblMessage.Enabled = false }
But this does:
protected void Page_Load(object sender, System.EventArgs e) { this.lblMessage.Enabled = false }
Are you sure you’re events are firing in the order you expect? Put breakpoints on all your postback methods and watch what happens, are you resetting the enabled state anywhere? do you have enableviewstate=false on anything?
Edit: You realise CheckedChanged doesnt fire until you postback from another control, or you have AutoPostBack=true on the checbkbox?
This works fine: