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

Setting SelectedDate on RadDateTimePicker but leaving it Empty on Page_Load

5 Answers 272 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Michael Malone
Top achievements
Rank 1
Michael Malone asked on 29 Nov 2011, 06:11 AM
I have a RadDateTimePicker that needs to stay empty when the page loads. When the user selects a time from the TimePopupButton, the Date & Time are populated in the RadDateTimePicker.  The problem is the date portion that's populated is always today's date. How can I default this to another date, for example DateTime.Now.AddDays(1)?

If I set the "SelectedDate" property to DateTime.Now.AddDays(1), then the date that's populated works as expected. But setting "SelectedDate" causes the RadDateTimePicker to display this date when the page loads. I need it to be empty on page load and only populated if the user selects something from the PopUpButtons. 

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 29 Nov 2011, 07:15 AM
Hello,

I am not quite sure about your scenario. Inorder to make the RadDateTimePicker empty on PageLoad there is no need of setting Selected property and it is default behavior that the RadDateTimePicker populate when user select something from the Picker.

Thanks,
Princy.
0
Michael Malone
Top achievements
Rank 1
answered on 29 Nov 2011, 04:57 PM
When the user clicks the TimePopUp and selects "8:00AM", the DateTimePicker is populated with today's day, "11/29/2011 8:00AM".  I would like to determine which date is populated when the user selects a time. For example, if the user selects "8:00AM", I want the DateTimePicker to be populated with "1/01/1999 8:00AM" instead of today's date of  "11/29/2011 8:00AM".
0
Princy
Top achievements
Rank 2
answered on 30 Nov 2011, 06:56 AM
Hello,

Try setting SelectedDate property as the date you want to show. Here is the sample code.

ASPX:
<telerik:RadDateTimePicker ID="radtmpck" runat="server" SelectedDate="1/01/1999">
</telerik:RadDateTimePicker>

Thanks,
Princy.
0
Michael Malone
Top achievements
Rank 1
answered on 30 Nov 2011, 05:49 PM
In my original post I said -

"If I set the "SelectedDate" property to DateTime.Now.AddDays(1), then the date that's populated works as expected. But setting "SelectedDate" causes the RadDateTimePicker to display this date when the page loads".  

I need the DateTimePicker to be empty on Page_Load.
0
Kevin
Top achievements
Rank 2
answered on 01 Dec 2011, 02:44 PM
Hello Michael,

Why don't you just format the time that is being entered to use the date you want. Like so:

DateTime newDate = DateTime.Today.AddDays(1);
DateTime formattedDate = new DateTime(newDate.Year,newDate.Month,newDate.Day,RadTimePicker.SelectedDate.Value.Hour,
    RadTimePicker.SelectedDate.Value.Minute, RadTimePicker.SelectedDate.Value.Second);

Now if you need this to work when editing an existing time, you could store the date portion that was used in a hidden field, so you can use it when saving the time again.

I hope that helps.
Tags
Calendar
Asked by
Michael Malone
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Michael Malone
Top achievements
Rank 1
Kevin
Top achievements
Rank 2
Share this question
or