
838
|
Chapter 42: The System.Web.UI.WebControls Namespace
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
To provide server-side validation, create an event handler for the ServerValidate event.
The string from the input control and the result of the validation is stored in the
provided ServerValidateEventArgs object. You can also perform client-side validation, which
can improve the responsiveness of your application by reducing the need for round
trips to the server. However, because client-side validation will not be performed in
some browsers and is easy to circumvent, it should never be used in place of server
validation. To use client-side validation, set the ClientValidationFunction to the name of a
JavaScript or VBScript function in the .aspx code portion of your page (not the code-
behind class). This script function should be in a language that the client browser can
understand, which means that JavaScript is the best choice if you are supporting non-
Microsoft browsers. The function must be in the form function ValidationFunctionName(source,
value), where value is the value to be validated. This function should return True or False to
indicate whether the validation succeeded. ASP.NET will take care of the code neces-
sary to display the corresponding error message. Note that this is a very bad idea if
your function uses ...