'How to cause textbox validation on button click automatically in c#
Windows Form Application C#
I have four TextBox on windows Form. i have written code to handle Text_Validating event for each textbox. Now when user clicks on submit Button i want those text_validating events to fire automatically.
Enabled CausesValidation property of Button.
We have something called validationGroup Property in ASP.net how it can be implemented in windows application
pls help me to solve this problem
thank you
Solution 1:[1]
One option is simply to call the validation method passing in a parameters necessary (nulls might work - showing code would help to determine if necessary).
Solution 2:[2]
I believe the Text_Validating event only fires when a control's focus changes. If you are interested in validation on submit you could do something which is proposed by user Bruce from this post.
Solution 3:[3]
Also, you can write own Validator controls like asp.net in Winforms with following validators:- .
RequiredFieldValidator
RegularExpressionValidator
CompareValidator
RangeValidator
CustomValidator
Here is a step by step explanation and walkthrough on how to extend Winforms with a custom validation library - http://msdn.microsoft.com/en-us/library/ms950965.aspx
Solution 4:[4]
On button click, go with:
if(ValidateChildren())
{
//do stuff
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Brad Semrad |
| Solution 2 | Community |
| Solution 3 | Angshuman Agarwal |
| Solution 4 | Unheilig |
