Created On:  03 January 2013

Problem:

Customer has created a Windows Forms application in Visual COBOL.

The Form has a textbox control and a button control labeled Save.
There is a validation event handler for the textbox which displays a message if the textbox is blank and sets e::Cancel to true.
The AutoValidate property for the window is EnablePreventFocus and its AcceptButton property is set to the save button. 

The button's text property is set to "&Save" so that ALT-S will cause the button's click event.
The button has a handler for the click event which closes the form.

If the textbox is left blank and the button is clicked, the validation fails and focus remains on the textbox which is correct. 
If text is then entered in the textbox and either ALT-S or ENTER is pressed, the validation event code successfully completes but the button's click event handler is not performed.

If the button is clicked again the click event will be fired.
The first validation which fails is somehow suppressing the click event that should happen after the second validation is successful.

How can I get this to work correctly?

Resolution:

Try setting the CausesValidation property of the button to false.

If the Textbox control has it's CausesValidation property set to true then the field will be validated and then the click event will be handled only if the button does not have its own validation event.