views:

49

answers:

2

I have created a custom control that inherit the TextBox, in that control i have override validating event and in validating event i have put validation that checks for the empty field.

Now when i use that control on my winform and when i click on save button it immediate fires save event.. the validation event of custom control fires and it displays the error message but still it does not stop the save event to fire....

the save button CauseValidation Property is set to true..

i have also put (this.ValidateChildren())

i have also put CancelEventArgs ce.Cancel = true; in Custom Textbox control

but neither working to stop the save event to fires..

i only want to fire Save event if Textbox is not empty.

validating event fires, shows message for empty field and immediate fires save event..

now if you got an idea then if you have solution then please provide solution..

A: 

Validating event of the textbox is fired only when cusor leaves that textbox. If you directly click on the save button, Validating event of the textbox will not be fired.

I think, on Save button you need to provide some validation to check if textbox is empty or not.

Hope this helps..