NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Validating Against a Range of Values

You can check that a user's entry falls within a specific range of values — for example, between two numbers, between two dates, or between alphabetic characters.

To validate against a range of values

  1. Add a RangeValidator control to the page and set the following properties:
    Property Setting
    ControlToValidate The ID of the control you are validating.
    ErrorMessage, Text, ValidationDisplay Properties that specify the text and location of the error or errors that will display if the user skips the control. For details, see Controlling Validation Error Message Display.
  2. Set the low and high values of the range by setting the MinimumValue or MinimumControl and MaximumValue or MaximumControl properties. These properties take strings representing either a constant value or the ID of a control from which the range value should be derived. (The control-based properties derive their values by extracting the other control's ValidationProperty property.) If you set both MinimumValue and MinimumControl, or both MaximumValue and MaximumControl, the control-based property takes precedence.
    Note   When validation is done against another control, invalid values in the other control are ignored and the validation passes. For details, see Special-Case Validation Results.
    Note   The validation control assumes that the user has entered data in the format specified by the page's locale setting.
  3. Set the Type to specify the data type of the range settings. The type is specified using the ValidationDataType enumeration, which allows you to use the type name String, Integer, Double, DateTime, or Currency. If the user's entry can't be converted — for example, it cannot be converted to a date — the validation fails.
    Note   If the user leaves a control blank, the control passes the range validation. To force the user to enter a value, add a RequiredField validation control as well. For details, see Validating a Required Entry.
  4. Add a test in your Web Forms code to check for validity. For details, see Testing Validity Programmatically.

See Also

  1. Validation Controls | Introduction to Validating User Input in Web Forms |