ASP.Net compare validator on valid Date but on different culture value
I want to validate date using (dd/MM/yyyy)
format. I am using CompareValidator of asp.net but it does not validating valid date on this format. It is validating date on (MM/dd/yyyy)
format. How to use compare validator with (dd/MM/yyyy)
format
I am using CV as:
<asp:CompareValidator ID="chkStartIsDate" runat="server"
Display="Dynamic" Operator="DataTyp开发者_如何学运维eCheck"
Type="Date" ControlToValidate="txtProjectStartDate"
ErrorMessage="Supply a valid start date" />
Thanks.
I think that if you set the Page culture to the dd/MM/yyyy culture, the validator will validate the input for you
Set the culture like this in your aspx.cs class:
protected override void InitializeCulture()
{
Page.Culture = CultureInfo.GetCultureInfoByIetfLanguageTag(LanguageShort).ToString();
Page.UICulture = CultureInfo.GetCultureInfoByIetfLanguageTag(LanguageShort).ToString();
}
精彩评论