我在验证结束日期时遇到问题>开始日期实际上是AJAX启用日期游侠的日期比较!!我想知道任何内置的日期范围验证器可用于AJAX ASP.net
<td align="left">
<asp:TextBox ID="txtFromDate" runat="server" Width="100px" style="text-align:justify" ValidationGroup="MKE" />
<asp:ImageButton ID="ImgBntCalc" runat="server"
ImageUrl="~/AJAXImages/Calendar_scheduleHS.png" CausesValidation="False" />
<cc1:MaskedEditExtender ID="MaskedEditExtender5" runat="server"
TargetControlID="txtFromDate"
Mask="99/99/9999"
MessageValidatorTip="true"
OnFocusCssClass="MaskedEditFocus"
OnInvalidCssClass="MaskedEditError"
MaskType="Date"
DisplayMoney="Left"
AcceptNegative="Left"
ErrorTooltipEnabled="True" />
<cc1:MaskedEditValidator
ID="MaskedEditValidator5"
runat="server"
ControlExtender="MaskedEditExtender5"
ControlToValidate="txtFromDate"
EmptyValueMessage="Date is required"
InvalidValueMessage="Date is invalid"
Display="Dynamic"
TooltipMessage="Input a date"
EmptyValueBlurredText="*"
InvalidValueBlurredMessage="*"
ValidationGroup="MKE" />
<cc1:CalendarExtender ID="CalendarExtender1" runat="server"
TargetControlID="txtFromDate"
PopupButtonID="ImgBntCalc" />
</td>
<td align="left">
<asp:Label ID="lblToDate" Text="To Date" runat="server">
</asp:Label>
</td>
<td align="left">
<asp:TextBox ID="txtToDate" runat="server" Width="100px" MaxLength="1" />
<asp:ImageButton ID="imgBtn2" runat="server"
ImageUrl="~/AJAXImages/Calendar_scheduleHS.png"
CausesValidation="False" />
<cc1:MaskedEditExtender ID="mskEditor" runat="server"
TargetControlID="txtToDate"
Mask="99/99/9999"
MessageValidatorTip="true"
OnFocusCssClass="MaskedEditFocus"
OnInvalidCssClass="MaskedEditError"
MaskType="Date"
DisplayMoney="Left"
AcceptNegative="Left"
ErrorTooltipEnabled="True" />
<cc1:MaskedEditValidator
ID="mskValidator"
runat="server"
ControlExtender="mskEditor"
ControlToValidate="txtToDate"
EmptyValueMessage="Date is required"
InvalidValueMessage="Date is invalid"
Display="Dynamic"
TooltipMessage="Input a date"
EmptyValueBlurredText="*"
InvalidValueBlurredMessage="*"
/>
<cc1:CalendarExtender ID="CalendarExtender2" runat="server"
TargetControlID="txtToDate"
PopupButtonID="imgBtn2" />
</td>
</tr>
答案 0 :(得分:1)
我会使用compareTo方法
推荐更强大的工作代码,如下所示DateTime dtFrom = DateTime.Parse(txt1.Text);
DateTime dtTo = DateTime.Parse(txt2.Text);
if(dtFrom == null){//respond from date was invalid
}
if(dtTo = null){//respond to date was in valid
}
if(dtFrom.CompareTo(dtTo) >= 0){//You hit Jackpot
}
CompareTo返回一个整数值
when < 1, dtFrom occurs earlier than dtTo
When = 0, dtFrom is equal to dtTo
When > 0, dtFrom occurs after the dtTo