Search This Blog

Friday, 14 October 2022

Quick Tips: Asp.net Webforms Validators

 Validators in Web forms

Validators in web forms are controls, that validate a user input based on a condition.

Multiple validators can validate the same input control

Validators are asp.net controls and they add client (JS) validations automatically based on property settings

Validators can only validate asp.net controls (not html controls)

1. RequiredFieldValidator: Empty values are not allowed.

Properties to set:

ControlToValidate

ErrorMessage

SetFocusOnError


2. CompareValidator: Compares the values in 2 controls

Properties to set:

ControlToValidate

ControlToCompare

ErrorMessage

SetFocusOnError

Operator (optional. If not set, it will compare for equality)

Type (optional. If not set, it will compare the values for string datatype)

3. RangeValidator

Properties to set:

ControlToValidate

ErrorMessage

SetFocusOnError

MaximumValue

MinimumValue

Type (optional. If not set, it will assume string datatype)


4. RegularExpressionValidator

Properties to set:

ControlToValidate

ErrorMessage

SetFocusOnError

ValidationExpression


5. CustomValidator: When none of the above fit the application requirement, custom validators are used

Properties to set:

ControlToValidate

ErrorMessage

SetFocusOnError

ClientValidationFunction

No comments:

Post a Comment