I have two date/time picker controls on a page. When the user clicks chooses the first date and time I want to automatically add the date to the second date/time picker and add an 1/2 hour to the time of the first date/time picker as the suggested date/time.
For example:
Date/time picker #1: 4-14-2009 10:00 AM
Date/time picker #2: 4-14-2009 10:30 AM (Automatically displayed on postback of first date/time picker)
I also need the user to be able to override the second date/time picker if they want to.
Also, is it possible to compare the two different date and times (after the second date/time is choosen) to make sure the second date/time is after the first date/time?
For example:
Good:
Date/time picker #1: 4-14-2009 10:00 AM
Date/time picker #2: 4-14-2009 10:30 AM
Bad:
Date/time picker #1: 4-14-2009 10:00 AM
Date/time picker #2: 4-12-2009 10:30 AM
Thanks,
Joe
For example:
Date/time picker #1: 4-14-2009 10:00 AM
Date/time picker #2: 4-14-2009 10:30 AM (Automatically displayed on postback of first date/time picker)
I also need the user to be able to override the second date/time picker if they want to.
Also, is it possible to compare the two different date and times (after the second date/time is choosen) to make sure the second date/time is after the first date/time?
For example:
Good:
Date/time picker #1: 4-14-2009 10:00 AM
Date/time picker #2: 4-14-2009 10:30 AM
Bad:
Date/time picker #1: 4-14-2009 10:00 AM
Date/time picker #2: 4-12-2009 10:30 AM
Thanks,
Joe
6 Answers, 1 is accepted
0
Hi Joe,
This can be achieved by handling the SelectedDateChanged event of the first date/time picker. For example:
As for the second question, you can use a compare validator.
Kind regards,
Peter
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
This can be achieved by handling the SelectedDateChanged event of the first date/time picker. For example:
<telerik:RadDateTimePicker ID="RadDateTimePicker1" runat="server" AutoPostBackControl="Both" |
Culture="English (United States)" OnSelectedDateChanged="RadDateTimePicker1_SelectedDateChanged"> |
<TimePopupButton ImageUrl="" HoverImageUrl=""></TimePopupButton> |
<TimeView CellSpacing="-1"> |
</TimeView> |
<DateInput AutoPostBack="True"> |
</DateInput> |
<Calendar UseRowHeadersAsSelectors="False" UseColumnHeadersAsSelectors="False" ViewSelectorText="x"> |
</Calendar> |
<DatePopupButton ImageUrl="" HoverImageUrl=""></DatePopupButton> |
</telerik:RadDateTimePicker> |
<telerik:RadDateTimePicker ID="RadDateTimePicker2" runat="server"> |
</telerik:RadDateTimePicker> |
protected void RadDateTimePicker1_SelectedDateChanged(object sender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e) |
{ |
RadDateTimePicker2.SelectedDate = e.NewDate.Value.AddMinutes(30); |
} |
As for the second question, you can use a compare validator.
Kind regards,
Peter
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0

Joe
Top achievements
Rank 2
answered on 15 Apr 2009, 12:46 PM
Thanks for the reply Peter, I used your code but it didn't work. Here's what I have:
DateTimePicker(s)
And here's the code behind....
Thanks,
Joe
DateTimePicker(s)
<telerik:RadDateTimePicker ID="RadDateTimePicker1" Runat="server" | |
AutoPostBack="True" AutoPostBackControl="Both" OnSelectedDateChanged="RadDateTimePicker1_SelectedDateChanged" | |
Culture="English (United States)" Width="170px"> | |
<TimePopupButton ImageUrl="" HoverImageUrl=""></TimePopupButton> | |
<TimeView runat="server" CellSpacing="-1" Interval="00:30:00"></TimeView> | |
<DateInput runat="server" AutoPostBack="True"> | |
</DateInput> | |
<Calendar UseRowHeadersAsSelectors="False" UseColumnHeadersAsSelectors="False" runat="server" | |
ViewSelectorText="x" ShowRowHeaders="False"></Calendar> | |
<DatePopupButton ImageUrl="" HoverImageUrl=""></DatePopupButton> | |
</telerik:RadDateTimePicker> | |
<telerik:RadDateTimePicker ID="RadDateTimePicker2" Runat="server" | |
AutoPostBack="True" AutoPostBackControl="Both" | |
Culture="English (United States)" Width="170px"> | |
<TimePopupButton ImageUrl="" HoverImageUrl=""></TimePopupButton> | |
<TimeView runat="server" CellSpacing="-1" Interval="00:30:00"></TimeView> | |
<DateInput runat="server" AutoPostBack="True"> | |
</DateInput> | |
<Calendar runat="server" UseRowHeadersAsSelectors="False" UseColumnHeadersAsSelectors="False" | |
ViewSelectorText="x" ShowRowHeaders="False"></Calendar> | |
<DatePopupButton ImageUrl="" HoverImageUrl=""></DatePopupButton> | |
</telerik:RadDateTimePicker> |
And here's the code behind....
Protected Sub RadDateTimePicker1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadDateTimePicker1.Load | |
Dim dt As New DateTime() | |
dt = RadDateTimePicker1.MinDate | |
dt = (New DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day + 1, 0, 0, 0)).AddDays(-30) | |
RadDateTimePicker1.MinDate = dt | |
RadDateTimePicker1.MaxDate = Date.Now | |
End Sub | |
Protected Sub RadDateTimePicker2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadDateTimePicker2.Load | |
Dim dt As New DateTime() | |
dt = RadDateTimePicker2.MinDate | |
dt = (New DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day + 1, 0, 0, 0)).AddMonths(-1) | |
RadDateTimePicker2.MinDate = dt | |
RadDateTimePicker2.MaxDate = Date.Now | |
End Sub | |
Protected Sub RadDateTimePicker1_SelectedDateChanged(ByVal sender As Object, ByVal e As Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs) | |
RadDateTimePicker2.SelectedDate = e.NewDate.Value.AddMinutes(30) | |
End Sub |
Thanks,
Joe
0
Hi Joe,
I tested your code but it worked fine I believe. Here is a video presentation of what I get at my end:
http://www.screencast.com/users/Peter_at_Telerik/folders/Jing/media/b2a3f94e-f218-4ec7-92c3-4298d7728b67
Attached is the test page I used with your code. Please, let me know if I am missing something.
All the best,
Peter
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
I tested your code but it worked fine I believe. Here is a video presentation of what I get at my end:
http://www.screencast.com/users/Peter_at_Telerik/folders/Jing/media/b2a3f94e-f218-4ec7-92c3-4298d7728b67
Attached is the test page I used with your code. Please, let me know if I am missing something.
All the best,
Peter
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0

Joe
Top achievements
Rank 2
answered on 20 Apr 2009, 04:22 PM
Peter, thanks for the update.
I ran your example and it work perfectly. I then compared it to my page and the code was identical so I started looking for other reasons why it wouldn't work.
I realized that I had the two datepicker controls in the Ajax Manager. Once I removed them from there, the code worked as expected!
Thanks for all the help!
Joe
I ran your example and it work perfectly. I then compared it to my page and the code was identical so I started looking for other reasons why it wouldn't work.
I realized that I had the two datepicker controls in the Ajax Manager. Once I removed them from there, the code worked as expected!
Thanks for all the help!
Joe
0

Joe
Top achievements
Rank 2
answered on 30 Apr 2009, 03:18 PM
For some reason this morning the code you provided (and has been working well) no longer works.
Here's the code that fails:
And here's the error message:
Any suggestions?
Thanks,
Joe
Here's the code that fails:
Protected Sub RadDateTimePicker1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadDateTimePicker1.Load | |
Dim dt As New DateTime() | |
dt = RadDateTimePicker1.MinDate | |
dt = (New DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day + 1, 0, 0, 0)).AddDays(-30) | |
RadDateTimePicker1.MinDate = dt | |
RadDateTimePicker1.MaxDate = Date.Now | |
End Sub | |
And here's the error message:
Year, Month, and Day parameters describe an un-representable DateTime. | |
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. | |
Exception Details: System.ArgumentOutOfRangeException: Year, Month, and Day parameters describe an un-representable DateTime. | |
Source Error: | |
Line 11: Dim dt As New DateTime() | |
Line 12: dt = RadDateTimePicker1.MinDate | |
Line 13: dt = (New DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day + 1, 0, 0, 0)).AddDays(-30) | |
Line 14: RadDateTimePicker1.MinDate = dt | |
Line 15: RadDateTimePicker1.MaxDate = Date.Now | |
Source File: C:\Inetpub\eon\Default2.aspx.vb Line: 13 | |
Stack Trace: | |
[ArgumentOutOfRangeException: Year, Month, and Day parameters describe an un-representable DateTime.] | |
System.DateTime.DateToTicks(Int32 year, Int32 month, Int32 day) +2739139 | |
System.DateTime..ctor(Int32 year, Int32 month, Int32 day, Int32 hour, Int32 minute, Int32 second) +19 | |
Default2.RadDateTimePicker1_Load(Object sender, EventArgs e) in C:\Inetpub\eon\Default2.aspx.vb:13 | |
System.Web.UI.Control.OnLoad(EventArgs e) +99 | |
System.Web.UI.Control.LoadRecursive() +47 | |
System.Web.UI.Control.LoadRecursive() +131 | |
System.Web.UI.Control.LoadRecursive() +131 | |
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436 | |
-------------------------------------------------------------------------------- | |
Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433 |
Any suggestions?
Thanks,
Joe
0
Hi Joe,
Can you open a support ticket and send us a simple working demo of the problem?
Sincerely yours,
Peter
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Can you open a support ticket and send us a simple working demo of the problem?
Sincerely yours,
Peter
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.