Validation Controls in Asp.net

As we all know that being a human we all have a set of rules and regulations in our life which help us to be a discipline person. I have also many rules in my life like How to talk? , How to behave? How to react in a particular situation? I can’t say that this rules and regulations are hurdles in my freedom as it help me to become a better person for the outside world. Similarly there is a concept of validations in the asp.net .Asp.net is used to design the number of forms to make a website. And the above validation concept improves the feature of those forms by applying rules on each field of that particular form. Till now I wrote many blogs about different languages and their features. But now I will talk about the validation controls which are another important topic of the asp.net language.

Asp.net Validation controls are used to validate each and every field of the Asp forms. These controls validate the user input data to ensure that unauthenticated, useless or doubtful data don’t get stored.

BaseValidator class: The validation controls are inherited from the BaseValidator class. This class contains the properties which are common for all the validation controls. Some of them are as follows:

Members Description
ControlToValidate Indicates the input control to validate.
ErrorMessage Indicates error string.

Asp.net provides the following validation controls:

  • RequiredFieldValidator
  • CompareValidator
  • RangeValidator
  • RegularExpressionValidator
  • ValidationSummary

Now, we discuss each control one by one:

  1. RequiredFieldValidator Validation Control: This control generally tied to the textbox to ensure that the required field is not empty. This validation control forces the user to input some data into each textbox.

Example:Name

  1. CompareValidator Validation Control: This control compares the value of one control with the fixed value of another control. This validation control ensures that the value in both controls should be same.
Properties Description
ControlToCompare It specifies the value of the input control to compare with.
ValueToCompare It specifies the constant value to compare with.

Example:

cPass 3. RangeValidator Validation Control: This control ensures that the user input value is fall within a predetermined range. Two important properties in this control are:

Properties Description
MinimumValue It specifies the minimum value of the range.
MaximumValue It specifies the maximum value of the range.

Example:

AgeRange (1) 4. RegularExpression Validation Control: This control validates the field by matching the user input against the regular expression pattern. The regular expression set in the ValidationExpression property.

Example:

confirmPassword 5. ValidationSummary: This validation control provides the summary of all the errors in the page. It does not perform any validation.The summary displays the values of the ErrorMessage property of all validation controls that failed validation. This control have two properties:

  • ShowSummary: shows the error messages in specified format.
  • ShowMessageBox: shows the error messages in a separate window.

Example:

valSumry for more info : cpd-india

Batches: Regular & Weekends for Working Profession

For FREE DEMO CLASS CALL – 011-65164822 / 91- 8860352748

CPD Technologies Block C 9/8, Sector -7, Rohini, Delhi-110085, India Landmark: Near Rohini East Metro Station, Opposite Metro Pillar No-397

Website :- www.cpd-india.com

Email :- support@cpd-india.com

Your email address will not be published. Required fields are marked *

Contact CPD Technologies