1

I'm using this code to validate two date but the validation is not working when I enter the same or after the Start Date

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

Do i need to use the hard code ?

Husna5207
  • 449
  • 3
  • 10
  • 28
  • what dates u r entering in ur textbox – Amit Singh Apr 16 '13 at 07:23
  • i enter by using date picker – Husna5207 Apr 16 '13 at 07:34
  • u have problem that when u enter same date it doesnt give error right....and when u left the start date blank than it doesnt give error thats two codntion only right – Amit Singh Apr 16 '13 at 07:38
  • when i left blank for both basic time picker, enter the same and after End Date its give the same Error Message – Husna5207 Apr 16 '13 at 07:44
  • after End Date means....what the date is coming in ur textbox pls let me know – Amit Singh Apr 16 '13 at 07:46
  • ops sorry, when i left blank for both basic date picker, enter the same and after Start Date its give the same Error Message. for example : Start Date : 16 April 2013 End Date : 17 April 2013 its pop-out the same Error Message – Husna5207 Apr 16 '13 at 07:49
  • The Format of Date You Are Entering Is not correct...see this http://stackoverflow.com/questions/9735836/asp-net-compare-validator-issue-while-specifying-date-format-in-calender-extende [1]: http://stackoverflow.com/questions/9735836/asp-net-compare-validator-issue-while-specifying-date-format-in-calender-extende – Amit Singh Apr 16 '13 at 07:57

1 Answers1

0

Aspx File:

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

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

Now Try this..................

Chetan Sanghani
  • 2,058
  • 2
  • 21
  • 36
  • thank you. but still not working. when i left blank for both basic time picker, enter the same and after End Date its give the same Error Message – Husna5207 Apr 16 '13 at 07:45