Click here to Skip to main content
15,169,185 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello everyone,i am using datetimepiker to pick date and time ,i want to check start date should not greater than end date and Date time Validation in asp.net

my datetime format is like this-2014-01-08 11:26

i am also using compare validation but not working

XML
<asp:CompareValidator ValidationGroup="examvalidation" ID="cmpVal1" ControlToCompare="txtstarttime"
                                                   ControlToValidate="txtendttime" Type="Date" Operator="GreaterThanEqual" ForeColor="Red"
                                                   ErrorMessage="Start date should not greater than end date" runat="server"></asp:CompareValidator>




please help me
Posted

1 solution

Upto my knowledge,you cant check the datetime format in compare validator,but you can check if only date.so,better
use custom validator

C#
protected void DateTimeComparision_ServerValidate(object source, ServerValidateEventArgs args)
    {
        args.IsValid = Convert.ToDateTime(txtStartDate.Text) < Convert.ToDateTime(txtFinishDate.Text);
    }
   
v2

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