Validation Server Controls

IOTA^_^    

Sams Teach Yourself ASP.NET in 21 Days, Second Edition
By Chris Payne
Table of Contents
Appendix C.  ASP.NET Controls: Properties and Methods


This section lists the detailed properties for each of the ASP.NET validation server controls. These controls are used to provide user input validation for other server controls.

Common Validation Server Control Properties

Table C.55 lists properties and methods that are common to all validation controls inherited from the System.Web.UI.WebControls.BaseValidator class except the ValidationSummary control.

Table C.55. Properties and Methods of the BaseValidator Class
Property Description
ControlToValidate Specifies the control that should be validated.
Display The display behavior for the validation control. Can be one of the following:

None The error message is not displayed.

Static If validation fails, the control's error message is displayed where the control resides in the page layout. The control will take up space in the layout even if the error message is not visible.

Dynamic Error messages are displayed when validation fails, and the control doesn't take up any space in the page layout if a message is not displayed.

EnableClientScript Specifies whether client-side script will be generated to handle validation client-side via DHTML. Note that client-side script must be created manually.
Enabled Indicates if the validation control is enabled.
ErrorMessage The message to display if the input is not valid.
ForeColor Sets the font color of the error message.
IsValid Specifies whether the input in the control specified by ControlToValidate is valid.
Method Description
GetValidationProperty Retrieves the validation property of a control.
Validate Determines whether the watched over server control's content is valid, and updates the IsValid property.

The Validation Server Controls

The following section lists the details of each validation control. Note that the ControlToValidate property must be set to a valid server control for these controls to function properly.

CompareValidator

This control compares values in a control to another value, or another control. Table C.56 lists the properties of this server control.

Table C.56. Properties of the CompareValidator Control
Property Description
ControlToCompare The ID of the control to compare values with.
Operator The comparison to make. Can be DataTypeCheck, Equal, GreaterThan, GreaterThanEqual, LessThan, LessThanEqual, or NotEqual.
ValueToCompare A constant value to compare against.

CustomValidator

This control validates controls' contents via a server-side or client-side validation routine, created by you. Table C.57 lists the properties and events of this server control.

Table C.57. Properties and Events of the CustomValidator Control
Property Description
ClientValidationFunction The client-side function that should be used to validate the specified control.
Event Description
ServerValidate Occurs during a form post; indicates which server-side method will be used to validate the control.

RangeValidator

This control compares values in a control against a possible range of values. Table C.58 lists the properties of this server control.

Table C.58. Properties of the RangeValidator Control
Property Description
MaximumValue The maximum allowed value for the watched over control's input. Can be a string or number.
MinimumValue The minimum allowed value for the watched over control's input. Can be a string or number.

RegularExpressionValidator

This control compares values in a control to a regular expression. Table C.59 lists the properties of this server control.

Table C.59. Properties of the RegularExpressionValidator Control
Property Description
ValidationExpression A regular expression to validate the watched-over control's content against.

RequiredFieldValidator

This control ensures that content is entered into a server control; it is not left blank. Table C.60 lists the properties of this server control.

Table C.60. Properties of the RequiredFieldValidator Control
Property Description
InitialValue The initial value associated with the watched-over control.

ValidationSummary

This control provides a central location for all other validation controls to display their error messages. It can be used in conjunction with the control's in-line error messages. Table C.61 lists the properties of this server control.

Table C.61. Properties of the ValidationSummary Control
Property Description
DisplayMode The display behavior of this control. Can be BulletList, List, or SingleParagraph.
EnableClientScript Indicates whether client-side validation should be used.
ForeColor The font color to display the error messages.
HeaderText The header displayed at the top of this control.
ShowMessageBox Indicates whether the error messages should be shown in a pop-up message box.
ShowSummary Indicates whether the validation summary is displayed inline.


    IOTA^_^    
    Top


    Sams Teach Yourself ASP. NET in 21 Days
    Sams Teach Yourself ASP.NET in 21 Days (2nd Edition)
    ISBN: 0672324458
    EAN: 2147483647
    Year: 2003
    Pages: 307
    Authors: Chris Payne

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net