ASP.NET Validation Controls

Are you preparing for IT certification? With practice questions, study notes, interactive quizzes, tips and technical articles, uCertify PrepKits ensure that you get a solid grasp of core technical concepts to ace your certification exam in first attempt.

ASP.NET Validation Controls

Rating:

ASP.NET provides a data validation framework for enabling validation of user input at the Web browser. Validation ensures that the user has input valid data into all required fields on a Web site. ASP.NET provides both client-side and server-side validation by facilitating Web pages with several validation controls. The user input validation at the client-side is beneficial, as it enhances Web site performance by checking the data entered by a user at the Web browser before sending it to the Web server. The client-side validation is also very useful, as it avoids unnecessary round trips to the Web server.

However, the client-side validation can be easily being tampered by any users. ASP.NET also provides server-side validation that is more secure than the client-side validation. Server-side validation validates user input data that is posted back to the Web server. ASP.NET 2.0 provides many validation controls that automatically provide data validation at both the server-side and the client-side.

ASP.NET performs validation by attaching one or more validation controls to both the HTML and Web server controls that accepts user inputs in a Web page. The ASP.NET validation controls provide a mechanism that tests user input data for valid dates or values within a given range. The controls also provide different ways to provide custom-written validation and also allow users to customize how error information is displayed on the Web site. The validation controls derive their functionality from the BaseValidator abstract class of the System.Web.UI.WebControls namespace. The various types of validation controls are as follows:

  • RequiredFieldValidator Control: The RequiredFieldValidator validation control ensures that the associated input control contains an entry in the Web page. The control contains the InitialValue property that specifies the initial value of the input control associated with the RequiredFieldValidator control. When the InitialValue property control is set to a value, users need to select or enter a value in the associated input control other than the value in the InitialValue property. Otherwise, the same values in the InitialValue property and the associated input control cause the validation to fail when the input control loses focus.


  • RegularExpressionValidator Control: The RegularExpressionValidator validation control checks whether the data in the associated input control matches a specific pattern. The control contains the ValidationExpression property that obtains a regular expression in a string to determine whether the pattern validates a required field. This property is used to check whether or not the certain characters such as e-mail addresses, telephone numbers, and postal codes are in sequence manner defined by the regular expression.


  • RangeValidator Control: The RangeValidator validation control checks whether the data is within the range of the associated input control. The ControlToValidate property of the RangeValidator Control specifies the input control that is to be validated. This property is set to the ID of an input control in order to validate it and that can be left blank in some cases. The ID that is used to set must refer to an input control that is within the same container in which the validation control resides. The MinimumValue and MaximumValue properties of the RangeValidator control specify the minimum and maximum values of the valid range, respectively.


  • CompareValidator Control: The CompareValidator validation control compares the values in an HTML or Web server input control such as TextBox control with values entered in another input control or a constant value. The control can also be used to determine whether the value entered can be converted to a data type that is specified by the BaseCompareValidator.Type property.

    The ControlToCompare property of the CompareValidator control is used to set an input server control to be compared with another control being validated. By default, the property value is set to String.Empty. If the input control is not a control of a Web page, an exception is thrown. The Operator property of this control is used to specify the comparison operation to perform on input controls. The operations of this property are Equal, NotEqual, GreaterThan, GreaterThanEqual, LessThan, LessThanEqual, and DataTypeCheck.

    The ValueToCompare property is used to specify a constant value to compare with the user input value entered in a server input control that is being validated. By default property value is String.Empty. If the constant value fails to convert to a data type that is specified by the BaseCompareValidator.Type property, an exception is thrown.


  • CustomValidator Control: The CustomValidator validation control performs customized or user-defined validations that are not provided by other validation controls to validate data. The control can be used to create server-side as well as client-side validation functions. The ServerValidate event for the CustomValidator control is raised when validation is performed on a Web server. This event is used for providing a custom validation routine for an input control.

    The ClientValidationFunction property of this control specifies the name of the custom client-side script function used for validation. The function contains the validation logic. The property should be set to the name of a script function that is sent to the browser. The ValidateEmptyText property of the CustomValidator control is used to specify a boolean value to indicate whether or not the empty text is validated. By default, the property value is set to String.Empty. This property is a new feature for the .NET Framework version 2.0.


Rating:



Other articles

Click here to Article home

Microsoft Certification MCSE: MCSA , MCTS, MCDST, MCAD, MCDBA, MCSE Messaging, MCSE Security
JAVA Certification: SCJP, SCWCD Cisco Certification: CCNA, CCENT, A+, Network+, Security+
Oracle Certification: OCP 9i, OCP 10g, OCA 9i, OCA 10g CIW foundation    Photoshop ACE
© 2008 uCertify.com. All rights reserved. All trademarks are the property of their respective owners.
 
HACKER SAFE certified sites prevent over 99.9% of hacker crime.