I’m developing an web application with asp.net and c#. I have a textbox in my page and it inputs a simple date. I’ve used CompareValidator to validate this textbox, but when the user input an specific date (3rd sunday of october, e.g.: 10/16/2011 or 10/17/2010 or 10/18/2009) the compare validator says it is invalid date. Does someone knows what is happening with it ?
My compare validator:
<asp:CompareValidator ID="cvDataProtocolo" runat="server"
ControlToValidate="txtDataProtocolo" Display="Dynamic"
ErrorMessage="Data Inválida"
SetFocusOnError="True" Type="Date" Operator="DataTypeCheck"
ValidationGroup="vProtocolo"></asp:CompareValidator>
Edits—–
Yes, I wrote 10/16/2011 just to understand, my culture is setup to pt-BR (portuguese Brazil) and in Brazil we use the format dd/MM/yyyy and the CompareValidator does not valid 16/10/2011 (in format dd/MM/yyyy) as a valid format. I’ve setted my culture in my webform:
protected override void InitializeCulture() {
Page.Culture = CultureInfo.GetCultureInfoByIetfLanguageTag("pt-BR").ToString();
Page.UICulture = CultureInfo.GetCultureInfoByIetfLanguageTag("pt-BR").ToString();
System.Threading.Thread.CurrentThread.CurrentCulture = New CultureInfo("pt-BR");
System.Threading.Thread.CurrentThread.CurrentUICulture = New CultureInfo("pt-BR");
}
Thank you
Ensure you have set your Culture correctly, as (for instance) in the UK, 10/16/2011 means the 10th day of the 16th month, which would be an invalid date.
See here for more information: http://msdn.microsoft.com/en-us/library/bz9tc508.aspx