Re: Can you cancel the click of a checkbox?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi,

It looks like the CheckState change is being performed by the OnClick handler of the CheckBox. If you want, you can create a derived CheckBox class and override the OnClick method, provide a new cancellable event (something like CheckStateChanging) that you call from your OnClick method, and only call the base OnClick method if the event is not cancelled.

Best regards,

Rodger

Sequence Diagram Editor - Draw sequence diagrams faster
<http://www.SequenceDiagramEditor.com>

Byron wrote:
I want to be able to intercept the click of a checkbox to cancel a change in its checked state under certain conditions to prevent the execution of code attached to the CheckedChanged event. So when someone clicks on the checkbox I want to do some validation and on failure throw the click away, leaving the state of the checkbox unchanged.

I was looking for Cancel or Handled to manage it, but I can't find it. I suppose I could short-circuit the CheckedChanged event to flip the checked state back and skip the code, using a Boolean flag to skip the second call to CheckedChanged when I change the state back, but that's ugly.

Any suggestions would be appreciated.
.



Relevant Pages

  • Re: How to determine what caused OnClick event for checbox
    ... As OnClick is fired not only when mouse clicked but also on other ... at the application level (keeping program state consistent with the ... handlers directly for some very poorly designed controls) _always_. ... Why do you care what made your checkbox ...
    (alt.comp.lang.borland-delphi)
  • Re: .innerText too slow - alternatives?
    ... "checkbox counter" value displayed at the top of the page. ... We tried putting a single TABLE onclick event - each time the table is ... You do not have to iterate over all the rows to count the checked items. ...
    (microsoft.public.scripting.jscript)
  • Re: Adding javascript event to datagrid control
    ... script on click of a checkbox; so onClick can be used. ... will run on server after a postback. ... > For a CheckBox server control, onClick attribute hooks a client-side JS ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Still not resolved. Need expert help
    ... I have no idea yet how to handle the onclick stuff. ... I am consulting the web ... > Curt Christianson ... That is, with the checkbox, the readonly ...
    (microsoft.public.inetserver.asp.general)
  • Re: winform
    ... You can simply modify this property in the event handler of the checkbox's CheckedChanged event and add new controls programmatically at that time. ... > I would like to have a form with three control and a checkbox control for more details, when they click on the checkbox the form should resize itself to show more contols ...
    (microsoft.public.dotnet.languages.csharp)