开发者

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();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜