Problem with MaskedEdit from Ajax Control Toolkit - different culture

Kjensen picture Kjensen · Apr 7, 2009 · Viewed 11.7k times · Source

I want to use maskededit to make the user to do the same as in the ajax control toolkit sample for maskededit, but I need to use another format, since dates at my client is displayed as dd-MM-yyyy. I also need to put a value in there to begin with, since the date is loaded from a db (once I get this code working, that is)

Look at this sample: http://www.asp.net/ajax/ajaxcontroltoolkit/samples/maskededit/maskededit.aspx

I need to do the same as in the textbox labeled "Enter Date (format: 99/99/9999): "

I downloaded the sample code and changed the format to "99-99-9999" in the relevant code:

But the sample date "12-12-1999" is not displayed in the textbox. Why not?

I cant figure out, what I am doing wrong. I also tried setting the cultureName to da-DK, but it did not chance anything. I also tried Chrome, Firefox and IE7, same behaviour...

How do I fix this?

<asp:TextBox ID="TextBox5" runat="server" Width="130px" MaxLength="1" style="text-align:justify" ValidationGroup="MKE">12-12-1999</asp:TextBox>
    <asp:ImageButton ID="ImgBntCalc" runat="server" ImageUrl="~/images/Calendar_scheduleHS.png" CausesValidation="False" />
    <ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender5" runat="server"
        TargetControlID="TextBox5"
        Mask="99-99-9999"
        MessageValidatorTip="true"
        OnFocusCssClass="MaskedEditFocus"
        OnInvalidCssClass="MaskedEditError"
        MaskType="Date"
        DisplayMoney="Left"
        AcceptNegative="Left"
        ErrorTooltipEnabled="True" />
    <ajaxToolkit:MaskedEditValidator ID="MaskedEditValidator5" runat="server"
        ControlExtender="MaskedEditExtender5"
        ControlToValidate="TextBox5"
        EmptyValueMessage="Date is required"
        InvalidValueMessage="Date is invalid"
        Display="Dynamic"
        TooltipMessage="Input a date"
        EmptyValueBlurredText="*"
        InvalidValueBlurredMessage="*"
        ValidationGroup="MKE" />

Answer

MaLKaV_eS picture MaLKaV_eS · May 25, 2009

I suposse you'll have this already fixed, but ... have you tried using UserDateFormat="DayMonthYear" ?

UserDateFormat="DayMonthYear"

<asp:TextBox ID="TextBox5" runat="server" Width="130px" MaxLength="1" style="text-align:justify" ValidationGroup="MKE">12-12-1999</asp:TextBox>
<asp:ImageButton ID="ImgBntCalc" runat="server" ImageUrl="~/images/Calendar_scheduleHS.png" CausesValidation="False" />
<ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender5" runat="server"
    TargetControlID="TextBox5"
    Mask="99-99-9999"
    MessageValidatorTip="true"
    OnFocusCssClass="MaskedEditFocus"
    OnInvalidCssClass="MaskedEditError"
    MaskType="Date"
    DisplayMoney="Left"
    AcceptNegative="Left"
    ErrorTooltipEnabled="True" **UserDateFormat="DayMonthYear"** />
<ajaxToolkit:MaskedEditValidator ID="MaskedEditValidator5" runat="server"
    ControlExtender="MaskedEditExtender5"
    ControlToValidate="TextBox5"
    EmptyValueMessage="Date is required"
    InvalidValueMessage="Date is invalid"
    Display="Dynamic"
    TooltipMessage="Input a date"
    EmptyValueBlurredText="*"
    InvalidValueBlurredMessage="*"
    ValidationGroup="MKE" />