CompareValidator验证两个日期 [英] CompareValidator to validate two dates
本文介绍了CompareValidator验证两个日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所有我使用以下格式的日期格式 dd-MMM-yy
我正在使用比较验证器来验证日期如下
Hi all I am having my date format in the following format dd-MMM-yy
I am using compare validator to validate the dates as follows
<asp:CompareValidator ID="cmpDates" runat="server" ControlToValidate="StartDate"
SetFocusOnError="true" ControlToCompare="EndDate"
ErrorMessage="EndDate must be greater than StartDate"
Display="None" Operator="DataTypeCheck"
ValidationGroup="vg" Type="Date"
CultureInvariantValues="true">
</asp:CompareValidator>
但是这不符合要求,有些人可以帮助我如何验证日期
But this is not working as per required so can some one help me how Can I validate the dates in the required format
推荐答案
尝试这个,这里我们使用Ajax calander控件来获取dd / mm / yyyy格式的输入,然后使用比较验证器
Try this, here we use the Ajax calander control to get the input in dd/mm/yyyy format and then use the compare validator
<asp:TextBox ID="txtStart" runat="server"></asp:TextBox>
<cc1:CalendarExtender ID="txtStart_CalendarExtender" runat="server"
Enabled="True" TargetControlID="txtStart">
</cc1:CalendarExtender>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="txtEnd" ControlToValidate="txtStart"
ErrorMessage="CompareValidator"></asp:CompareValidator>
</div>
<p>
<asp:TextBox ID="txtEnd" runat="server"></asp:TextBox>
<cc1:CalendarExtender ID="txtEnd_CalendarExtender" runat="server"
Enabled="True" TargetControlID="txtEnd">
</cc1:CalendarExtender>
</p>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
这篇关于CompareValidator验证两个日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文