Click here to Skip to main content
14,700,043 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have used compare validator and range validator to validate date field but when i enter 13/20/11 or 20/20/24 i got error : Error while converting datetimePlzz help

<tr>
            <td><b>Re-Contact Date :</b> </td>
            <td><asp:TextBox ID="txtReminderDate" runat="server" Width="70px" />
            <asp:CompareValidator ID="cvReminderDate" ValidationGroup="a" runat="server" ControlToValidate="txtReminderDate" Type="Date" ErrorMessage="Please Enter Valid Date" Display="None" Operator="DataTypeCheck" SetFocusOnError="true"></asp:CompareValidator>
            <asp:RangeValidator runat="server" ID="rvReminderDate" Type="Date" ValidationGroup="a"  ControlToValidate="txtReminderDate" MaximumValue="01/01/9999" MinimumValue="01/01/1900" ErrorMessage="Reminder date can not less then 01/01/1900" Display="None" SetFocusOnError="True" />
            <asp:RequiredFieldValidator ID="rfvReminderDate" ValidationGroup="a" runat="server" ErrorMessage="Please Enter Date." Display="None" SetFocusOnError="true" ControlToValidate ="txtReminderDate"></asp:RequiredFieldValidator>
            </td>
          </tr>
Posted

u need to use regex validator as well to validate the input string as date then the compare and range validation would work according to your plans.
   
Comments
k@ran 25-Jan-13 0:03am
   
@Hasham Ahmad:

Please give me an example of using compare with regex validator.
When you enter a datetime inside textbox. Your validator start to convert this text to date time and then that datetime will be compared for your min and max value.
When you enter Wrong datetime. Validator starts to convert that into date. before comparing.
So when you enter 13/20/11 or 20/20/24 which is wrong date time. you got the error before comparison.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900