This is a migrated thread and some comments may be shown as answers.

DateTime Picker and Min Date

2 Answers 202 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Craig
Top achievements
Rank 1
Craig asked on 09 Apr 2010, 06:13 AM
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.

Thanks,
Craig

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimo
Telerik team
answered on 09 Apr 2010, 12:57 PM
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" />
<title>RadControls</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
 
<telerik:RadDatePicker ID="RadDatePicker1" runat="server">
    <ClientEvents OnDateSelected="MyDateSelected" />
</telerik:RadDatePicker>
 
<script type="text/javascript">
 
function MyDateSelected(sender, args)
{
    if (!args.get_newDate())
        return;
 
    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)
        sender.clear();
}
 
</script>
 
</form>
</body>
</html>


Regards,
Dimo
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.
0
Craig
Top achievements
Rank 1
answered on 09 Apr 2010, 04:23 PM
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.

Thanks,
Craig
Tags
Calendar
Asked by
Craig
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Craig
Top achievements
Rank 1
Share this question
or