I am using the leave event of a text box to validate a username and password - the problem is if the user has started to enter data in the text box and they decide to press the cancel button - the leave event on the text box does not need calling. Is there a way to stop the leave event happening if the cancel button is pressed. can I use the 'try and catch' thing and check if the click event on cancel has happened? If so can some on explain try catch as i have never used it. Like what is optional and compulsory and how the logic flows through it?
---------------------
Solved it like this
if (!btnChangePasswordCancel.Focused) [this is inside the leave event]
dont validate the text
Loading
Mayur GujrathiPosted Apr 15, 2011, 9:15 AM
under click event of cancel button do like this
canclebutton.CausesValidation=false
due to this cancel button executes before doing any validations
you can also set this property by right clicking on button and set cause validation to false
VulpesPosted Apr 15, 2011, 6:50 AM
Sam HobbsPosted Apr 15, 2011, 2:29 AM
In C++ there is something called MFC. MFC has a very sophisticated ability to perform validation. Experienced MFC developers would insist that it is very poor design to validate fields when an Okay button is clicked.
I am neutral. It does not matter to me; both ways can be useful, depending on requirements. It is interesting that people can be so adamant (demanding) that one of the two options are the only good way.
Except I will say this much. Microsoft C# programmers seem less object-oriented. They don't use derivation as much as Microsoft MFC programmers do. An object-oriented solution to validation would be done by deriving a control from a control and do the validation in the derived control. That would be entirely possible if the validation did not include other controls. Validation logic such as what MFC has would include logic to avoid validation when the form is canceled. I am surprised that .Net does not.
Suthish NairPosted Apr 14, 2011, 2:46 PM
VulpesPosted Apr 13, 2011, 11:09 AM
I thought when I read the question that it was just a normal 'logon' dialog though I see from the addition to your original post that you've figured out a way to avoid validation in the Leave event in any case, if the user presses the cancel button.
Richard BrennanPosted Apr 13, 2011, 11:02 AM
But i have done what u said on the normal logon form.
VulpesPosted Apr 13, 2011, 10:16 AM