There are various validation controls provided by ASP.NET. They are added to the controls for validating the input values added by the user. Range Validator RequiredField Validator Regular expression validator Compare validator Custom validator Validation summary BaseValidator class The validator consists of the properties inherited from the BaseValidator class. The properties and methods used by the validation controls are as listed below. Display: The error message used for the specific value is shown ControlToValidate: The control to be validated is assigned by the user ErrorMessage: The error value shown when the validation is performed EnableClientScript: The client side validation is initiated Validate(): The control is validated and the IsValid property is validated Range Validator The range validator is used for checking the values defined in a specific range. Properties of the range validator are: BackColor: The background color of the web server control is assigned. BindingContainer: The data binding of the control is defined Context: The HttpContext object associated with the server control is defined Display: The error message to be shown when the validation control is stated EnableTheming: The value used for showing the themes applied to the control ID: The identifier assigned to the server control MinimumValue: The minimum value of the validation is assigned MaximumValue: The maximum value of the validation is assigned Style: The text attributes which are rendered as the style attributes are defined Some of the methods of Range Validator. AddedControl: Once the child control is added to the collection, it is called by the user ApplyStyle: The non empty elements are applied a specific style to the control ClearChildState: The view state and control state information for the controls is removed DataBind: Used for binding the data source to the server control and child controls Finalize: The resources are removed from the system and are garbage collected HasControls: If there are child controls present in the server controls OnLoad: The Load event is raised by the user Syntax of range validator: Code: <asp:RangeValidator ID="rg1" runat="server" ControlToValidate="TextBox1" MinumumValue="10" MaximumValue="50" ErrorMessage="Values not in range" Type="Integer" > </asp:RangeValidator> RequiredField Validator The required field validator is used to check that the field contains value. Some of the properties of the required field validator are: Attributes: The collection of the attributes not corresponding to the properties is shown. ClientID: The control ID for the HTML markup created by ASP.NET ControlToValidate: The input control to be validated by the user Display: The behavior of the error message in the validation control is shown. ErrorMessage: The error message for the control when it fails validation ID: The unique identifier for the control is defined Width: The width of the control can be assigned Some of the methods of the required field validator are AddedControl: It is called when the child control is added to the collection ApplyStyle: The non empty elements stated by the style of the control are copied. ClearChildControlState: The control state information is deleted from the server child controls Focus: Provides the focus to the control HasEvents: The value stating the events registered for the controls and the corresponding child controls SaveViewState: The state is saved which is modified after the method was invoked ToString: The string stating the current object is returned Validate: The validation with the corresponding control is performed Syntax of RequiredField Validator: Code: <asp:RequiredFieldValidator ID="field1" runat="server" ControlToValidate="textbox1" ErrorMessage="Value must be added"></asp:RequiredFieldValidator> Regular expression validator The validator is used for validating the value present in the control is similar to the expression defined. Some of the properties of RegularExpressionValidator are: AccessKey: Provides the access key used for navigating the server control Context: The HttpContext object associated with the control is retrieved CssClass: The CSS class is rendered through the web server control Display: The display of the error message in the validation control is defined Events: The list of event handler used as delegates for the control ID: The identifier associated with the specific server control is defined SkinID: The skin to be added to the control is defined TemplateControl: The reference of the template is defined Some of the methods of the RegularExpressionValidator are: BuildProfileTree: The information about the server control is collected and provided as an input to the Trace property ClearChildControlState: User for removing all the information of view and control state for all the server controls EndRenderTracing: The design time rendering of the data is ended Finalize: The object is allowed to free the resources and the cleanup operations are performed GetType: The Type of the current instance is provided OnBubbleEvent: It checks if the server control is passed to the page UI server control structure ResolveUrl: The URL is converted to the usable one by the client SetDesignModeState: The design time data for the control is set Syntax for RegularExpression validator is: Code: <asp:RegularExpressionValidator ID="reg1" runat="server" ControlToValidate="Control1" ErrorMessage="Show the string" ValidationExpression="string" > </asp:RegularExpression> Compare validator It is used for comparing the values added by the user in the input control or with a constant value defined by the user. Properties of Compare validator: BindingContainer: It provides the control consisting of the data binding BorderWidth: The border of the control can be modified ControlStyle: The style of the web server control is defined Enabled: The value stating the validation control is enabled or not Events: The list of event handler delegate to the control are provided Operator: The operator used for the comparison is defined TemplateControl: The reference of the template of the control is provided ValueToCompare: It accesses or assigns the value which is compared by the user value Methods of Compare Validator: AddAtttributesToRender: The attributes of the control are added to the output stream. BeginRenderTracing: The design time rendering of the data is performed EndRenderTracing: The design time rendering is stopped by the user GetControlRenderID: The clientID for the control is retrieved IsLiteralContent: It checks whether the server control contains literal content OpenFile: The stream used for reading the file Syntax for Compare Validator: Code: <asp:CompareValidator ID="Compare1" runat="server" ControlToValidate="control1" ControlToCompare="control2" ErrorMessage="Values must match" Operator="Equals"> </asp:CompareValidator> Custom validator The user defined validations are performed on the user control. The client and server side validation are used. The ClientValidationFunction property is used to perform the client side validation. The ServerValidate event is used for validating the server side. Properties of custom validator: Adapter: The browser related adapter for the control is defined ControlStyle: The style for the web server control is defined ControlToValidate: The control validated for the user inputs DesignMode: The value stating the control used in the design surface IdSeperator: The character used to change the identifiers Parent: The reference to the server control is defined Methods of custom validator: AddParsedSubObject: The notification for every element parsed and added ClearChildState: The view state and control state for the servers child controls is defined ControlPropertiesValid: It checks whether the control contains valid values DetermineRenderUplevel: It decides whether the validation control can perform client side validation GetHashCode: The hash function for the control is retrieved RemovedControl: Once the child control is removed, it is called by the user SaveControlState: The server control state changed are modified by the user Syntax for custom validator control is: Code: <asp:CustomValidator ID="custom1" runat="server" ClientValidationFunction="function1" ErrorMessage="CustomValidator values" > </asp:CustomValidator> Validation summary The Validation summary control is used for displaying the error messages present on the web page. The ErrorMessage property is used for showing the values when the validation is not performed. Syntax for Validation summary: Code: <asp:ValidationSummary ID="validation1" runat="server" DisplayMode="BulletList" ShowSummary="false" > </asp:ValidationSummary> Example to demonstrate the validation controls in an ASP.NET application Open Visual Studio application in your system. Create a web application In the source view, add the following code. Code: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <table style="width:77%";> <tr> <td colspan="3" align="center"> <asp:Label ID="lbl1" runat="server" Text="Student admission form" > </asp:Label> </td> </tr> <tr> <td> StudName: </td> <td> <asp:TextBox ID="Text1" runat="server"></asp:TextBox> </td> <td> <asp:RequiredFieldValidator ID="req1" runat="server" ControlToValidate="Text1" ErrorMessage="Value must be added" > </asp:RequiredFieldValidator> </td> </tr> <tr> <td> StudAge: </td> <td> <asp:TextBox ID="text2" runat="server"></asp:TextBox> </td> <td> <asp:RangeValidator ID="range1" runat="server" MaximumValue="50" MinimumValue="20" ControlToValidate="text2" ErrorMessage="Values not in range" > </asp:RangeValidator> </td> </tr> <tr> <td> Email: </td> <td> <asp:TextBox ID="text3" runat="server"></asp:TextBox> </td> <td> <asp:RegularExpressionValidator="reg1" runat="server" ControlToValidate="text3" ErrorMessage="Email not in proper format" ValidationExpression="\w+([-+.’)\w+)*@\w+([-.]\w+)*\.\w+([-.])\w+)*" > </asp:RegularExpressionValidator> </td> </tr> <tr> <td> <asp:Button ID="btn1" runat="server" Text="Show" /> </td> </tr> </table> <asp:ValidationSummary ID="valid1" runat="server" DisplayMode="BulletList" ShowSummary="true" /> </div> </form> </body> When the code is compiled and executed, the following result is displayed.