Duration: 20 minutes
Summary: In this video, we will build our own validation control class. To do so we add a class to the site. This class inherits from BaseValidator and implements the EvaluateIsValid method. As the name implies, this method returns a boolean that indicates whether the value entered by the user in the control to validate is valid or not. To get the value to validate, we use the method GetControlValidationValue. In our case, we needed to check for two things: (1) The value entered meets the minimum length requirement (2) it has at least 1 character. We are simulating the password validation. We create another method in the class named HasNumeric() to make sure the user entered at least 1 number. After we finish building the class, we create a page to test our custom validator. We register the class at the top of the page giving it a tag prefix of “cv” for custom validator. We add the usual properties for the validator (id, ControlToValidate, Text, runat), and the specific property MinLength so the user can dynamically specify the minimum length of the password.
Methodology of the development of example: Good coding standard and simplified design to illustrate the key points.
Technology Used: ASP.NET and Visual Studio 2010Keyword: ASP.NET 4, Visual Studio 2010, Custom Validator, BaseValidator, ControlToValidate, Text, EvaluateIsValid, GetControlValidationValue