Search code examples
asp.netweb-applications

Validate Numeric TextBox Entries Asp.Net


In Asp.Net or Web-Developemnt what is the best way to ValidateTextBox's on a page. The TextChange event (server side) happens after you leave the textbox which is too late. I was going to use a Double.TryParse on server side.


Solution

  • The accepted best practice is to use a Validator control.

    The CompareValidator can be used to verify the Data Type by changing the "Operator" property to "DataTypeCheck".

    You could also use a RegularExpressionValidator for the same effect.

    If you need to do a type check and ensure the value is withing a specified range, you would use a RangeValidator.