140 likes | 237 Views
CSCI 6962: Server-side Design and Programming. Validation Controls. ASP Validation Controls. ASP automatically reposts same page, echoes original values back Validation controls can be attached to other controls to insure they contain legal values
E N D
CSCI 6962: Server-side Design and Programming Validation Controls
ASP Validation Controls • ASP automatically reposts same page, echoes original values back • Validation controls can be attached to other controls to insure they contain legal values • IsValidoperator used in conditions that cause page redirection • Can specify client-side or server-side validation
Validation Controls • In Validation section of Toolbox • Usually dragged next to corresponding control so errormessage displayed next to it • Control must have CausesValidation property setto true
Validation Control Properties • Key properties shared by all: • ID • ControlToValidateControl this validator is associated with • ErrorMessageMessage to display in validator if value is not valid • EnableClientScriptFalse to force JavaScript-based validation on server side(must be set to avoid errors)
Required Field Validator • Requires control to have a value • Strings trimmed before evaluation • Can be used on any list-based control
Required Field Validator • Can set InitialValue property • Validation checks whether the property has changed • Useful if control has a value (lists, for example)
Validation and Redirection • Usually only redirect to next page if all fields valid on current page • Can check with Page.IsValid • Make part of condition for redirection
Compare Validator • Used to compare control value to some limit • ValueToCompare: limiting value • Operator: How comparison done • Equal, NotEqual, GreaterThan, GreaterThanEqual, LessThan, LessThanEqual C
Compare Validator • Can also be used for type checking • Operator = DataTypeCheck • Set Type property C C
Regular Expression Validator • Key property: ValidationExpression • ASP provides list of commonly used expressions C
Regular Expression Validator • Can create own regular expression in expression chooser C C
Multiple Validators • Often attach multiple validators to same control if more than one property must be validated • Example: WidgetBox • Must have value (RequiredValidator) • Must be an integer (CompareValidator with DataTypeCheck) • Must be at least 1 (CompareValidator with GreaterThanEqual) • Must set Display property to Dynamic • Otherwise, “space” for inactive validator present C
Custom Validation • Writing code for validation • Function called: IDofValidator_ServerValidate
Custom Validation • Purpose: Set args.IsValid flag (True if valid False if not) C