Csharp control validating

The internets are full of trivial examples, but I couldn't find a single non-trivial example explaining control validation.

Anyway, thanks to Sw Dev Man81 and Hans Passant I am starting from a much better place than yesterday.

Validation controls are used to: Client side validation is good but we have to be dependent on browser and scripting language support. NET Web pages for user input is to be able to check that the information users enter is valid. NET provides a set of validation controls that provide an easy-to-use but powerful way to check for errors and, if necessary, display messages to the user. NETUsually, Validation is invoked in response to user actions like clicking submit button or entering data.

csharp control validating-33csharp control validating-46

The main advantage is that it prevents a page from being postback to the server until the client validation is executed successfully. Server validation will only performed when Cause Validation is set to true. You can have a Required Field Validator control for each form element on which you wish to enforce Mandatory Field rule.

For developer point of view serve side is preferable because it will not fail, it is not dependent on browser and scripting language. NET validation, which will ensure client, and server validation. When the value of the Causes Validation property is set to true, you can also use the Validation Group property to specify the name of the validation group for which the Button control causes validation. Compare Validator Control The Compare Validator control allows you to make comparison to compare data entered in an input control with a constant value or a value in a different control.

Is there a simple way of triggering validating/validated event on the button? I tried placing textbox on the form and tabbing between button and textbox, but neither of those events get triggered.

I am trying to better understand how validation works in a Windows Forms application.

There are many different forms where data can be entered and I would like to not go control by control by form and create is Valid etc per item. I see that most related posts deal with Web Apps and/or mention Enterprise Library Validation Application Block.

Comments