locked
MASKEDEDITEXTENDER control need to validate dd/MM/yyyy format only RRS feed

  • Question

  • User-1050146888 posted

    I have used a MASKEDEDITEXTENDER control on my ASP NET 2.0 with VB 2005 to validate a bound date field.

    The date validation works provided i enter it in the format : MM/dd/yyyy . But, i get a STRING NOT RECOGNISED AS A VALID DATETIME when i enter in the format dd/MM/yyyy.

    How can i solve this ? I need to validate dd/MM/yyyy format only.

    Thanks,

    Alex 

     

    Thursday, July 5, 2007 4:11 PM

Answers

  • User-1050146888 posted

    Dear Juan,

    Thanks for your help. I finally got the DATE value insert into the SQL db. I read elsewhere & added the foll. code to the web.config file

    <system.web>

    <globalization culture="en-NZ" />

    </system.web>

     <SYSTEM.WEB><GLOBALIZATION culture="en-NZ"></SYSTEM.WEB>......WALLAH>>>>>>>>>>>>>>>> It worked like a charm.....!!

    Thanks,

    Alex

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, July 7, 2007 8:03 AM

All replies

  • User1618900539 posted

     Hi Alex,

    I use the MaskedEditExtender to validate the same format (dd/MM/yyyy). Here is the code I use to create it programatically and it works, I'm sure you can apply it to your scenario:

     

     Dim masked As New AjaxControlToolkit.MaskedEditExtender
     masked.ID ="id"
     masked.TargetControlID = textbox.ID
     masked.MaskType = AjaxControlToolkit.MaskedEditType.Date
     masked.CultureName = "en-nz"
     masked.MessageValidatorTip = False
     masked.Mask = "99/99/9999"

     

    Cheers,
                    

    Thursday, July 5, 2007 4:52 PM
  • User-1050146888 posted

    Hi Juan,

    I cannot seem to get it work with your code. My code is as follows: 

     <asp:TextBox ID="VisitDateTextBox" runat="server" Text='<%# Bind("VisitDate") %>'> </asp:TextBox><br />
                                <cc2:MaskedEditExtender ID="MaskedEditExtender1" CultureName="en-nz" runat="server" mask="99/99/9999" 
                                    MaskType="Date" MessageValidatorTip="true" OnFocusCssClass="MaskedEditFocus"
                                    OnInvalidCssClass="MaskedEditError" TargetControlID="VisitDateTextBox">
                                </cc2:MaskedEditExtender>

     

    Could u please help ? I tried changing the DATE in Regional settings of my PC to dd/MM/yyyy format, but still no luck

    Thanks,

    Alex 

    Thursday, July 5, 2007 5:56 PM
  • User1618900539 posted

     Alex,

    Your  Windows regional settings won't affect here. What will affect are the Explorer language settings, but by setting a CultureName you are "hard-coding" it (maybe you don't need "en-nz", just pick the one that suits you)

    Anyway, could you please try the following?

    Add a MaskedEditValidator, like this:

    Dim maskedval As New AjaxControlToolkit.MaskedEditValidator
    maskedval.ControlExtender = masked.ID
    maskedval.ControlToValidate = textbox.ID
    maskedval.InvalidValueMessage = "* (dd/mm/yyyy)"

    Then, remove for a moment the databinding and enter values manually. What result do you get there? 

     

    Thursday, July 5, 2007 6:12 PM
  • User-1050146888 posted

    Hi Juan,

    Thanks for your replies. I tried ur solution. It accepts and validates dates entered & gives error when enter invalid dates. The problem happens when submitting  the value to the SQL db. It gives the String not recognized as valid DATETIME.

    My code is as follows: 

    <asp:TextBox id="VisitDateTextBox" runat="server" text="<%# Bind("VisitDate") %>"></asp:TextBox><asp:TextBox ID="VisitDateTextBox" runat="server" Text='<%# Bind("VisitDate") %>'> </asp:TextBox><br />

                                <cc2:MaskedEditExtender ID="MaskedEditExtender1" CultureName="en-nz" runat="server" mask="99/99/9999" 
                                    MaskType="Date" MessageValidatorTip="true" OnFocusCssClass="MaskedEditFocus"
                                    OnInvalidCssClass="MaskedEditError" TargetControlID="VisitDateTextBox">
                                </cc2:MaskedEditExtender>
                                <cc2:MaskedEditValidator ID="MaskedEditValidator1" runat="server" ControlExtender="MaskedEditExtender1"         ControlToValidate="VisitDateTextBox"
                                 Display="Dynamic" TooltipMessage="Please enter a Date" InvalidValueMessage="The date is invalid">
                                </cc2:MaskedEditValidator><br />
    <cc2:MaskedEditExtender id="MaskedEditExtender1" culturename="en-nz" runat="server" mask="99/99/9999" masktype="Date" messagevalidatortip="true" onfocuscssclass="MaskedEditFocus" oninvalidcssclass="MaskedEditError" targetcontrolid="VisitDateTextBox"> </cc2:MaskedEditExtender> <cc2:MaskedEditValidator id="MaskedEditValidator1" runat="server" controlextender="MaskedEditExtender1" controltovalidate="VisitDateTextBox" display="Dynamic" tooltipmessage="Please enter a Date" invalidvaluemessage="The date is invalid"> </cc2:MaskedEditValidator>Please help !!

    Thanks again,

    Alex  

    Friday, July 6, 2007 5:33 PM
  • User1618900539 posted

    Hi Alex,

     I'm glad it's working, at least the extender part...

    About the SQL, I don't know if there is a way to format the datetime field in a different way, I'm not a SQL expert, sorry for not being more helpful here! :)

    Friday, July 6, 2007 9:20 PM
  • User-1050146888 posted

    Dear Juan,

    Thanks for your help. I finally got the DATE value insert into the SQL db. I read elsewhere & added the foll. code to the web.config file

    <system.web>

    <globalization culture="en-NZ" />

    </system.web>

     <SYSTEM.WEB><GLOBALIZATION culture="en-NZ"></SYSTEM.WEB>......WALLAH>>>>>>>>>>>>>>>> It worked like a charm.....!!

    Thanks,

    Alex

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, July 7, 2007 8:03 AM
  • User52571275 posted

    I have added <globalization> in web.config but my datetime format (dd/mm/yyyy) doesn't work. Well, I also hard code when Page_Init .It's still not work as well.

    Can someone help me?
    Reguards,

    Nicky

    Monday, August 11, 2008 12:14 AM
  • User1384820898 posted

    MaskType="Date" Mask="99-99-9999" UserDateFormat="DayMonthYear"

    Thursday, June 11, 2009 4:16 AM