how to validate date time picker with today's date and time

5 posts, 1 answers
  1. atif iqbal
    atif iqbal avatar
    7 posts
    Member since:
    Feb 2010

    Posted 05 Mar 2010 Link to this post

    I have rad datetimepicker control. i want that if user enter date and also time part which is greater than today's date and time then validation message appear.
  2. robertw102
    robertw102 avatar
    265 posts
    Member since:
    Jul 2007

    Posted 05 Mar 2010 Link to this post

    Just compare the date with the current one like so:

    RadDateTimePicker1.SelectedDate.Value > DateTime.Now

    The DateTime.Now gets the current date and time on the server.

    I hope that helps.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. atif iqbal
    atif iqbal avatar
    7 posts
    Member since:
    Feb 2010

    Posted 08 Mar 2010 Link to this post

    yes, you are correct but i want that when user select date or time and if its greater than today's date and time then immediatley validation occur. i do not want to validate it when another event fire or on postback. thanks
  5. Answer
    robertw102
    robertw102 avatar
    265 posts
    Member since:
    Jul 2007

    Posted 08 Mar 2010 Link to this post

    If you want to validate it on the client-side then create a javascript function and assign it to the ClientValidationFunction property of a CustomValidator control.

    The validation function would look something like this:
    function ValidateDateTime(sender,args) 
    var todaysDate = new Date(); // gets current date/time
    var dateTimePicker = $find("<%=RadDateTimePicker1.ClientID%>"); // gets selected date/time
     
    if (dateTimePicker.get_selectedDate() > todaysDate) 
    args.IsValid = false
    else 
    args.IsValid = true

    I hope that helps.
  6. atif iqbal
    atif iqbal avatar
    7 posts
    Member since:
    Feb 2010

    Posted 09 Mar 2010 Link to this post

    yea, it works for me, thanks
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017