2013-04-16 136 views
1

開始日期我正在使用此代碼來驗證兩個日期,但驗證不工作時,我輸入相同的或開始日期後驗證的結束日期應大於或等於在asp.net

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

我需要使用硬代碼嗎?

+0

什麼日期你輸入你的文本框 –

+0

我通過使用日期選擇器輸入 – Husna5207

+0

你有問題,當你輸入相同的日期,它不會給錯誤正確....當你離開始日期空白比它不給錯誤,這兩個密碼只有權利 –

回答

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> 

銫文件:

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

現在試試這個..................

+0

謝謝。但仍然無法正常工作。 當我留空兩個基本時間選擇器, 輸入相同和結束日期後它給出相同的錯誤信息 – Husna5207

+0

現在你可以試試這個...使用設置這種類型的屬性....... –

相關問題