Search code examples
asp.net.net-2.0ajaxcontroltoolkit

ASP.NET AJAX toolkit MaskEditExtender Date autocomplete mask


I'm using the asp.net ajax toolkit maskeditextender to mask a textbox for date input. Problem is, though, I can't get it to validate against the date they enter properly. If I turn off autocomplete mask and they type 7 slash 6 slash 88 it will fill in "07/06/88" which, funny enough, is not a valid date. If I autocomplete the mask it should autocomplete to "07/06/1988" but it autocompletes to "07/06/0088" even though I set the century to 1900...

Any advice?

My Solution:

So, autocomplete is terrible. You'd probably have to write some JS to put a 19 in front of the YY because it just appends 00. So you get "07/06/0088"...

As the answerer suggested I turned autocomplete off but it would still not validate the date right. I was using a compare validator against the date datatype. But as it turns out it needs a very specific format:

"07/06/1988"

and nothing else. So, I wrote a custom validator that padds zeros to the month and day and 19 to the year. Also, when I used the txt box's value I had to replicate the same fix to get it convert to datetime without throwing an exception.


Solution

  • I've seen this issue before and there are a few differnet fixes. Are you setting the MaskType to "Date" or "None"? If you're using Date, you may need to write some custom code to autocomplete with the correct digits. If you're using None, you should be able to force the four-digit year which will effectively eliminate the autocomplete issue. This is probably the route that I'd suggest you go becasue you can still restrict the input to digits and validate the input as a date, but you dont have to worry about it autocompleting the wrong century.