C
Chad
I have a textbox control, txtMeasurement, that I want to allow only numeric decimal input. I thought to use a client side validation control to ensure that the data entered is of type "Double".
'Measurement Validation (Range Validator)
Dim MeasurementRangeValidator As New RangeValidator 'validate that the measure is numeric
MeasurementRangeValidator.ControlToValidate = txtMeasurement.ID|
MeasurementRangeValidator.Display = ValidatorDisplay.Dynamic
MeasurementRangeValidator.Type = ValidationDataType.Double|
MeasurementRangeValidator.CssClass = "validatorerrormessage"
MeasurementRangeValidator.MinimumValue = CType(-999999999999, Double).ToString 'essentially allow any value, we are just checking to make sure that it is numeric
MeasurementRangeValidator.MaximumValue = CType(999999999999, Double).ToString
However, if the user types a dash ("-") in the text box, the validation control's edit is passed but my program blows up on the following line:
Dim dblMeasurement as Double = CTYPE(txtMEasurement.Text, Double)
It fails because it is unable to convert a "-" to a Double data type!
By the way, this also does not work:
This function returns TRUE:
BaseCompareValidator.CanConvert("-", ValidationDataType.Double)
but
Dim dblMyDouble As Double = CTYPE("-", Double)
fails!
Is there some way to get the Validation control to fire when and only when the user enters data that cannot be converted to a Double datatype?
'Measurement Validation (Range Validator)
Dim MeasurementRangeValidator As New RangeValidator 'validate that the measure is numeric
MeasurementRangeValidator.ControlToValidate = txtMeasurement.ID|
MeasurementRangeValidator.Display = ValidatorDisplay.Dynamic
MeasurementRangeValidator.Type = ValidationDataType.Double|
MeasurementRangeValidator.CssClass = "validatorerrormessage"
MeasurementRangeValidator.MinimumValue = CType(-999999999999, Double).ToString 'essentially allow any value, we are just checking to make sure that it is numeric
MeasurementRangeValidator.MaximumValue = CType(999999999999, Double).ToString
However, if the user types a dash ("-") in the text box, the validation control's edit is passed but my program blows up on the following line:
Dim dblMeasurement as Double = CTYPE(txtMEasurement.Text, Double)
It fails because it is unable to convert a "-" to a Double data type!
By the way, this also does not work:
This function returns TRUE:
BaseCompareValidator.CanConvert("-", ValidationDataType.Double)
but
Dim dblMyDouble As Double = CTYPE("-", Double)
fails!
Is there some way to get the Validation control to fire when and only when the user enters data that cannot be converted to a Double datatype?