
98
|
Chapter 5: ASP.NET Server Controls
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
Validation Controls
ASP.NET removes the hassle of duplicating validation code, a common problem
of performing data validation using classic ASP, by neatly encapsulating the stan-
dard validations into server controls. You can declaratively relate the validation
control to the control whose value needs to be validated, using the ControlToVali-
date attribute. You can also attach multiple validation controls to a single control.
The ASP.NET validation server controls provide server-side validation for all
browsers and supply client-side validation via JavaScript for browsers that support
JavasScript and DHTML. You can also write your own custom client and/or
server-side validation functions, as you’ll see in the code example for this section.
One feature that most web programmers would like to have is a summary of the
validation errors for the values entered into a page’s controls. The ValidationSum-
mary control provides this much-desired feature. Table 5-6 lists the validation
controls.
The simplified syntax of the validation controls is as follows:
<asp:comparevalidator id="cvCompare"
controltovalidate="value1"
controltocompare="value2"
operator="equal"
type="integer"
errormessage="Fields are not equal!"
display="dynamic"
runat="server"/>
<asp:customvalidator ...