ASP.NET- Validation Controls

Whenever you want to check the data entered by users is valid or not then you are supposed to add validation controls. ASP.NET has validation framework that allows developers to create client-side and server-side controls with minimum coding.

Client Side validation controls are easy to create and are convenience to users. It improves performance by checking the data at browser before sending it to the server. But it comes with a drawback that client side controls are easily defeated by hackers. So in case of sensitive data server-side validation is preferred for posting back the data to the server.


 Many sites developed using asp.net makes use of both client and server side controls for secure user-experience and less overhead to server. Client side validation can be disabled by setting Enableclientscript property to false. The page.validate method can be explicitly called to force validation.

The web page’s isvalid property can be queried to verify that the page is valid before running the code.  

Some validation controls are: - RequiredFieldValidator - CustomValidator - RegularExpressionValidator - CompareValidator - RangeValidator - ValidationSummary

 The “validationsummary” control can be added to a web page to show a summary of the validation on the web page and as a pop-up message. The Regularexpressionvalidator is used to specify the validation patterns. The customvalidator allows you to provide your own custom client-side or server side code to perform validation.  

Adding Validation Control to aspx page using visual studio

 You can find validation controls in the visual studio toolbox like any other controls. Follow the steps as explained below to add validation controls to your page. 1. Open visual studio and open up the page in design view. 2. Visual studio toolbox and go to Validation tab of toolbox. 3. Drop the desired control on page. 4. Depending on control you can set the properties of the control like ControlToValidate, ErrorMesage,Tooltip.