tags:

views:

1331

answers:

3

I have an asp.net textbox and a MaskedEditExtender control attached to it. The textbox is used for date input. The MaskedEditExtender has MaskType="Date" Mask="99/99/9999".

When the form is submitted with an invalid date, the browser shows a Javascript error "... string was not recognized as a valid datetime".

I know why the error shows up. Is there a way to use the extender to just control what the user enters and not validate or convert the input?

A: 

on the text box you and set up a keypress function.

Validate if the key pressed is a number String.fromCharCode(event.which) or event.keycode (ie or FF)

Then can check that the text box is contains valid code and format.

If invalid you can set to a default that is valid or just prevent the keypress by using preventDefault()

if invalid format can disable the submit button also ....

Good luck

Brad8118
Are saying not to use the MaskedEditExtender? Otherwise that's the job of the control so that I don't have to do all this work. That's what maskedits do. Plus I want to just the mask itself.
Abdu
Never mind. It was a code behind exception in my code which wasn't caught. Thanks.
Abdu
A: 

Don't specify mask type as "Date", that should stop this error.

NimsDotNet
+2  A: 

Stop the form from submitting with an invalid date. Use a MaskedEditValidator

edosoft