Pages

Saturday, April 26, 2008

CustomValidator Control

The controls described up to this point generally focuses on validating one or two fields based on specific, bounded parameters. Typical requirements, however, usually fall outside the capabilities of the intrinsic controls. In anticipation of this, the creators of ASP.NET made the CustomValidator control. The CustomValidator control provides you with an opportunity to create custom validation logic for situations requiring complex business rules validation.

Like other validation controls, the CustomValidator control exposes common properties such as ControlToValidate, Display, ErrorMessage, Text, and ValidationGroup. Also like other validation controls, the CustomValidator control supports both server-side and client-side validation. To associate custom server logic with the control, you must override the ServerValidate event. One of the parameters of the event handler for this event is an object of type ServerValidateEventArgs. Based on the results of the custom validation logic, you can set the IsValid property of the ServerValidateEventArgs object. For client-side validation, you must create a JavaScript function and reference that function using the ClientValidationFunction property of the CustomValidator control.

No comments: