DateTime Picker and Min Date

3 posts, 1 answers
  1. Craig
    Craig avatar
    24 posts
    Member since:
    Aug 2006

    Posted 09 Apr 2010 Link to this post

    I am having an issue with the min date on the date time picker and setting the DbSelectedDate in code behind.

    I have a form that the user can select a date and time for work to be done (start date/time). I set the min date in code behind to prevent them from selecting a data in the past. This all works great.

    My problem is that when the user goes back to the form after the work has started the date displays the current date and time. It looks like a validation error is forcing the date to Now().

    I am looking for some elegant solution or a clever hack. Basically I don't want the user to pick a date in the past but still display the date in the text box. i am hoping I can still use this control because it wokes perfectly for the UI.

  2. Answer
    Dimo avatar
    8478 posts

    Posted 09 Apr 2010 Link to this post

    Hello Craig,

    RadDatePicker cannot hold a value, which is invalid (out of range). So one option is to set MinDate only if the control does not have a value. Another option is to not set MinDate at all and validate selected dates on the client with the OnDateSelected handler.

    <%@ Page Language="C#" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    <head runat="server">
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <telerik:RadDatePicker ID="RadDatePicker1" runat="server">
        <ClientEvents OnDateSelected="MyDateSelected" />
    <script type="text/javascript">
    function MyDateSelected(sender, args)
        if (!args.get_newDate())
        var dateNoTime = new Date(args.get_newDate().getFullYear(), args.get_newDate().getMonth(), args.get_newDate().getDate(), 0, 0, 0);
        var now = new Date();
        var nowNoTime = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0);
        if (dateNoTime < nowNoTime)

    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Craig
    Craig avatar
    24 posts
    Member since:
    Aug 2006

    Posted 09 Apr 2010 Link to this post

    Thanks Dimo.

    That's what I was thinking. I am already doing some client (and server) side code to prevent specific days from being selected. I think your solution is a good one. I was hoping I could just set a property somewhere.

    I have to say I am very happy with the Telerik control set. Overall it performs 95% of what I want to do. Every once in a while there is a strange/complex design pattern that needs some heavy lifting but the Telerik API is very robust.

Back to Top