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 Data Type

You can validate a user's entry against a specific data type to be sure that what the user has entered is a number, date, and so on.

To validate against a data type

  1. Add a CompareValidator control to the page and set the following properties:
    Property Setting
    ControlToValidate The ID of the control for which you are checking the data type.
    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 data type to compare to by setting the following properties:
    • Type The data type to check against. The type is specified using the ValidationDataType enumeration, which allows you to use the type names String, Integer, Double, DateTime, or Currency.
    • Operator   Set this property to DataTypeCheck.
Note   If the user leaves a control blank, the control passes the comparison validation. To force the user to enter a value, add a RequiredField validation control as well. For details, see Validating a Required Entry.
  1. 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 | Controlling Validation Error Message Display | Controlling Client versus Server Validation