且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

CompareValidator中的日期格式问题

更新时间:2023-01-29 08:51:14


尝试在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 property CultureInvariantValues="true" in your CompareValidator .

--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>