This documentation is archived and is not being maintained.

Client-Side Validation for ASP.NET Server Controls

If the user is working with Internet Explorer 4.0 or later, validation controls can perform validation using client script. Because the controls can provide immediate feedback (without a round trip to the server), the user experience with the page is enhanced.

Under most circumstances, you do not have to make any changes to your page or to the validation controls to use client-side validation. The controls automatically detect if the browser supports DHTML and perform their checking accordingly. Client-side validation uses the same error display mechanism as server-side checking.

Security Note   Validation is performed on the server even if it was already performed on the client. This allows you to check validation status in server code and provides security against users bypassing validation.

Differences in Client-Side Validation

There are some additional features of validation available if it is performed on the client:

There are a few minor differences associated with client-side validation:

  • If client-side validation is enabled, the page includes references to script libraries that are used to perform the client-side validation.
  • When you use a RegularExpressionValidator control, the expressions can be checked on the client if an ECMAScript-compatible language (such as Microsoft JScript) is available. This differs in some very small details from the regular expression checking done on the server using the System.Text.RegularExpressions.Regex class.
  • The page includes a client-side method to intercept and handle the OnClick event before the page is submitted.

Client Validation Object Model

Validation controls present almost the same object model on the client as on the server. For example, you can test validation by reading the value of a validation control's IsValid property the same way on both the client and the server.

However, there are differences in the validation information exposed at the page level. On the server, the page supports properties; on the client, it contains global variables. The following table compares the information exposed on the page.

Client Page VariableServer Page Property
Page_Validators (array)   Contains references to all validation controls on the page.Validators (collection)   Contains references to all validation controls.
Page_ValidationActive   A Boolean value that indicates whether validation should take place. Set this variable to False to turn off client-side validation programmatically.(no equivalent)
Note   All page-related validation information should be considered read-only.

Posting with Client-Side Validation Errors

Client-side validation is enabled automatically if you are using Microsoft Internet Explorer 4.0 or later. In some instances, however, you might prefer to use only server-side validation, even if client-side validation is available. For example, client-side validation might not be possible if the validation requires information or resources that are only available on the server, such as access to a database.

By default, when client-side validation is being performed, the user cannot post the form to the server if there are errors on the page. However, you might find it necessary to allow the user to post even with errors. For example, you may have a "Cancel" button or a navigation button on a page, and you want the button to submit the page even if some controls would fail validation. For more information, see Disabling Validation for ASP.NET Server Controls.

Note   Client-side validation requires that your browser support ECMAScript 1.2 (JScript) or later, and a Document Object Model (DOM) compatible with Internet Explorer 4.0 or later.

See Also

Web Forms Validation | Disabling Validation for ASP.NET Server Controls