locked
localization issue with datetime validation RRS feed

  • Question

  • User166150723 posted

    I am trying to use en-GB localization, so have the following setup in my web.config in the system.web part...

    <globalization
               fileEncoding="utf-8"
               requestEncoding="utf-8"
               responseEncoding="utf-8"
               culture="en-GB"
               uiCulture="en-GB"
            />

    but when I put a compare validation control on a text control containing a uk date (i.e. 28/01/2008), the validation fails telling me it's an invalid date. Is there something else I need to do?

    Thanks

     Simon
     

     

     
     

    Thursday, March 6, 2008 2:54 AM

Answers

  • User1817007508 posted

     Hi,

        Set the CultureInvariantValues="true".


    • Culture Invariant Values - When doing conversion on a compare validator's non strongly-typed properties (CompareValidator.ValueToCompare, RangeValidator.MaximumValue, RangeValidator.MinimumValue) the validator will use a culture neutral format (Date: YYYY/MM/DD, Double & Currency: US culture format) to do the conversion when CultureInvariantValues is true.

              http://dotnetjunkies.com/QuickStartv20/aspnet/doc/validation/default.aspx

    Hope it helps 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, March 8, 2008 4:57 PM

All replies

  • User1817007508 posted

     Hi,

        Set the CultureInvariantValues="true".


    • Culture Invariant Values - When doing conversion on a compare validator's non strongly-typed properties (CompareValidator.ValueToCompare, RangeValidator.MaximumValue, RangeValidator.MinimumValue) the validator will use a culture neutral format (Date: YYYY/MM/DD, Double & Currency: US culture format) to do the conversion when CultureInvariantValues is true.

              http://dotnetjunkies.com/QuickStartv20/aspnet/doc/validation/default.aspx

    Hope it helps 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, March 8, 2008 4:57 PM
  • User166150723 posted

    Thanks for the reply but it didn't make a difference. My validor looks like this

     <asp:CompareValidator runat="server"
                ControlToValidate="FromDate"
                Operator="DataTypeCheck"
                CultureInvariantValues="true"
                Type="Date"
                ErrorMessage="Please enter a valid date (dd/mm/yyyy)" EnableClientScript="true">
            </asp:CompareValidator>

    Any further ideas?

    Cheers, Simon
     

    Monday, March 10, 2008 7:51 AM
  • User189827543 posted

    Hi,

     Try the following code. Here Calenderextender is an ajax control.

      <asp:TextBox runat="server" ID="txtDate"></asp:TextBox><img alt="" id="cal" src="close.gif" />
                <cc1:CalendarExtender TargetControlID="txtDate" PopupButtonID="cal" ID="CalendarExtender1"
                    runat="server">
                </cc1:CalendarExtender>
                <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="txtDate"
                    Operator="DataTypeCheck" CultureInvariantValues="true" Type="Date" ErrorMessage="Please enter a valid date (dd/mm/yyyy)"
                    EnableClientScript="true">
                </asp:CompareValidator>

     

    set the CalenderExtender 's Format property through code behind like this

    CalendarExtender1.Format = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;

    try this and let me know. 

     

    Tuesday, April 8, 2008 2:43 AM
  • User-2109426844 posted

    Hi,


    More details about setting the property and fixing this error can be found here



    Monday, December 7, 2009 5:39 PM