views:

436

answers:

1

I want to use the MaskedEditExtender to mask short dates. The problem is that I want to mask the field depending on the user language settings. This is working for a lot of cases, but for example for Latvian Culture (with format 9999.99.99. ) is not working.

<cc1:MaskedEditExtender  ID="MaskedEditExtender1" runat="server" AutoComplete="True" MaskType="Date" TargetControlID="myTextbox" ClearMaskOnLostFocus="True" 
   OnInvalidCssClass="myInvalidCss" OnFocusCssClass="myOnFocusClass" Mask="99/99/9999" >
</cc1:MaskedEditExtender>

Is there a simple way to set the Mask property with the user culture mask format? Am I missing something to do this easier?

A: 

Not sure why the extender won't recognize Latvian culture, but try looking at the overrides provided, such as CultureDateFormat and CultureDecimalPlaceholder. More info at the AJAX Control Toolkit sample website.

EDIT: Response to OP's comments:

I have not idea if this works, but it looks like you can get the short date format for a culture from the CultureInfo class, like this.

string shortDateFormat = 
      System.Globalization.CultureInfo.DateTimeFormat.ShortDatePattern

Take a look here for examples.

Matthew Jones
It does not recognize the latvian culture because I have "hardcoded" the Mask Value (Mask="99/99/9999")
Matias
Is there a reason you must have the Mask Value hardcoded? Could you just assign it based on when the user arrives to the page and what culture s/he is in?
Matthew Jones
I should do that. and that's the question, how can I do that? thanks for your answer
Matias
I replaced by hand with RegEx the ShortDatePattern to get the needed mask string from, i.e. dd/MM/yyyy to 99/99/9999. There should be a easier solution.
Matias