1

我正在使用此代码验证两个日期,但是当我输入相同日期或在开始日期之后验证不起作用

        <asp:CompareValidator ID="dateCompareValidator" runat="server" 
        ControlToValidate="EndDate"
        ControlToCompare="StartDate" 
        Operator="GreaterThanEqual" Type="Date"
        ErrorMessage="The second date must be after the first one.<br /><br />">
        </asp:CompareValidator>

我需要使用硬代码吗?

4

1 回答 1

0

.aspx 文件:

   <tr>
                        <td align="right">
                            Start Date:
                        </td>
                        <td align="left">
                            <telerik:RadDatePicker ID="RadDtpFromDate" runat="server" Calendar-EnableShadows="true" AutoPostBack="true"
                                Culture="en-IN" DateInput-DateFormat="dd-MMM-yyyy" DateInput-EmptyMessage="DD-MMM-YYYY"
                                ShowPopupOnFocus="true" ToolTip="Input Date" ZIndex="30001" 
                                onselecteddatechanged="RadDtpFromDate_SelectedDateChanged" />
                            <asp:RequiredFieldValidator runat="server" ID="rfvFromDate" Display="None" ControlToValidate="RadDtpFromDate"
                                InitialValue="" ValidationGroup="FinalSave" ErrorMessage="From Date is Mandatory"
                                ForeColor="Red"></asp:RequiredFieldValidator>
                            <ajaxToolkit:ValidatorCalloutExtender ID="vceFromDate" TargetControlID="rfvFromDate"
                                runat="server">
                            </ajaxToolkit:ValidatorCalloutExtender>
                            <asp:CustomValidator ID="cvFromDate" runat="server" ControlToValidate="RadDtpFromDate"
                                Display="None"></asp:CustomValidator>
                            <ajaxToolkit:ValidatorCalloutExtender ID="vceRadFromDate" runat="server" TargetControlID="cvFromDate">
                            </ajaxToolkit:ValidatorCalloutExtender>
                        </td>
                        <td align="right">
                            End Date:
                        </td>
                        <td align="left" colspan="2">
                            <telerik:RadDatePicker ID="RadDtpToDate" runat="server" Calendar-EnableShadows="true" AutoPostBack="true"
                                Culture="en-IN" DateInput-DateFormat="dd-MMM-yyyy" DateInput-EmptyMessage="DD-MMM-YYYY"
                                ShowPopupOnFocus="true" ToolTip="Input Date" ZIndex="30001" 
                                onselecteddatechanged="RadDtpToDate_SelectedDateChanged" />
                            <asp:RequiredFieldValidator runat="server" ID="rfvToDate" Display="None" ControlToValidate="RadDtpToDate"
                                InitialValue="" ValidationGroup="FinalSave" ErrorMessage=" To Date is Mandatory"
                                ForeColor="Red"></asp:RequiredFieldValidator>
                            <ajaxToolkit:ValidatorCalloutExtender ID="vceToDate" TargetControlID="rfvToDate"
                                runat="server">
                            </ajaxToolkit:ValidatorCalloutExtender>
                            <asp:CustomValidator ID="cvToDate" runat="server" ControlToValidate="RadDtpToDate"
                                Display="None"></asp:CustomValidator>
                            <ajaxToolkit:ValidatorCalloutExtender ID="vceRadToDate" runat="server" TargetControlID="cvToDate">
                            </ajaxToolkit:ValidatorCalloutExtender>
                        </td>
                    </tr>  

Cs 文件:

 if (RadDtpFromDate.SelectedDate > RadDtpToDate.SelectedDate)
            {
              dateCompareValidator.IsValid = False;
                return;
            }

现在试试这个......

于 2013-04-16T07:25:30.873 回答