views:

509

answers:

2

Background: I have a form with a "clear form" and a "cancel" button. If I have invalid data inside a dropdown and click either of these buttons the dropdown's validating event fires. I've added code to the validating event to succeed when either "clear" or "cancel" are pressed.

Problem: I would expect that the next thing that will happen is that the button-click events will fire. In the case of the "cancel" button it does. But the event for the "clear" button does not. I can't see any difference between the two buttons/events. What's going on and how do I fix this?

+1  A: 

Not sure what's ailing you, neither Click event should run when you set e.Cancel in a Validating event handler. But there's a better way to do this. Set the buttons' CausesValidation property to False.

Hans Passant
TY, the CausesValidation property was exactly what I needed! Spent over an hour yesterday trying all sorts of silly work arounds. Really appreciate it.
Jeff
A: 

I came across another similar scenario. In searching for an answer I came across this old question that I'd asked months agao! In this case the validation events moved the focus off the origional field so by the time the button event was ready to fire it couldn't. Ended up solving it by explicitely calling the button-click event from the validation.

Jeff