Saturday, January 29, 2011

ASP.NET Validator

1. add a validator to a field such as textbox
2. set the "cause validation" property true for the textbox
3. set the "autopostback" property true for the textbox
4. while click on a button, check if Page.isValid
This is server-side examination to avoid 'javascript' being turned off maliciously in client-side browser.
If we want to validate manually, skip 2, 3,
then in 4, call page.Validate("VGroup"), before check Page.isValid.
"VGroup" is the name of the validation group the textbox belongs to.
set the "validation group" property as "VGroup" for textbox.

There are some kinds of validator available, such as 'RequireValidation' and 'RangeValidation'.
'RequireValidation' means the field is required and the validator will check if this field is filled up.
'Range Validation' is to check the input value of the field.

No comments:

Post a Comment