views:

3876

answers:

3

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" />
A: 
<asp:TextBox ID="TextBox5" runat="server" Width="130px" MaxLength="10" style="text-align:justify" ValidationGroup="MKE" Text="12-12-1999"></asp:TextBox>

I am wondering if you move the text to the actual text attribute, if that would make a difference... I don't have the most recent version of AjaxToolkit other wise I would try it my self... Oh I just noticed is your max length really set to one or is that a copy and paste error? That would cause problems too.

J.13.L
The maxlength was actually an error in there, but not the source of my problems, unfortunately. I have also tried setting the text-value in the text-attribute, no luck...
Kjensen
+1  A: 

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" />
MaLKaV_eS
+1  A: 

I use " ValidationExpression" in MaskedEditValidator replace userDateFormat type Date dd/MM/yyy is very good. This is ValidationExpression="(((((0[1-9])|(1\d)|(2[0-8]))\/((0[1-9])|(1[0-2])))|((31\/((0[13578])|(1[02])))|((29|30)\/((0[1,3-9])|(1[0-2])))))\/((20[0-9][0-9])|(19[0-9][0-9])))|((29\/02\/(19|20)(([02468][048])|([13579][26]))))"

And in MaskedEditExtender put MaskType="none". Validate ok.

Nmducit