CompareValidator中的日期格式问题 [英] Date format problem in CompareValidator
本文介绍了CompareValidator中的日期格式问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< asp:TextBox ID txt_dateofjoin " runat 服务器" / < cc1:CalendarExtender ID =" runat 服务器" TargetControlID txt_dateofjoin" 格式 dd-MM-yyyy" TodaysDateFormat dd-MM-yyyy" > < >
< asp:TextBox ID =" runat 服务器" / < cc1:CalendarExtender ID =" runat 服务器" 格式 dd-MM-yyyy" TargetControlID =" =" dd-MM-yyyy" >
< /cc1:CalendarExtender >
< asp:CompareValidator ID =" runat 服务器" ControlToCompare txt_dateofjoin" ControlToValidate txt_confirmationdate" 操作员 =" 类型 =" SetFocusOnError =" 显示 =" 文本 =" 确认日期必须大于加入日期" / >
当我将CalendarExtender的格式更改为MM-dd-yyyy时,它可以正常工作,但在dd-MM-yyyy中,比较验证器将日期考虑为月份.现在,我如何才能以dd-MM-yyyy格式验证这两个日期.
解决方案
尝试在CompareValidator
中设置属性CultureInvariantValues="true"
.
--Amit
通过以下方式重写日历扩展器的标签,即可解决您的问题...
< cc1:CalendarExtender ID =" runat =" 服务器" TargetControlID txt_dateofjoin" 格式 =" TodaysDateFormat dd/MM/yyyy" ">< /cc1:CalendarExtender >
>
<asp:TextBox ID="txt_dateofjoin" runat="server" />
<cc1:CalendarExtender ID="cal2" runat="server" TargetControlID="txt_dateofjoin" Format="dd-MM-yyyy" TodaysDateFormat="dd-MM-yyyy"></cc1:CalendarExtender>
<asp:TextBox ID="txt_confirmationdate" runat="server" />
<cc1:CalendarExtender ID="cal" runat="server" Format="dd-MM-yyyy" TargetControlID="txt_confirmationdate" TodaysDateFormat="dd-MM-yyyy">
</cc1:CalendarExtender>
<asp:CompareValidator ID="cmpDates" runat="server" ControlToCompare="txt_dateofjoin" ControlToValidate="txt_confirmationdate" Operator="GreaterThan" Type="Date" SetFocusOnError="true" Display="Dynamic" Text="Confirm Date must be greater than Joining Date" />
when I change the Format of CalendarExtender to MM-dd-yyyy then it works fine but in dd-MM-yyyy compare validator consider date to month. Now how I can validate this two date in dd-MM-yyyy format.
解决方案
Hi,
Try setting the propertyCultureInvariantValues="true"
in yourCompareValidator
.
--Amit
Rewrite your tag for calender extender in following way its solved your problem...
<cc1:CalendarExtender ID="cal2" runat="server" TargetControlID="txt_dateofjoin" Format="dd/MM/yyyy" TodaysDateFormat="dd/MM/yyyy"></cc1:CalendarExtender>
这篇关于CompareValidator中的日期格式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文