Setting SelectedDate on RadDateTimePicker but leaving it Empty on Page_Load

6 posts, 0 answers
  1. Michael Malone
    Michael Malone avatar
    68 posts
    Member since:
    May 2010

    Posted 29 Nov 2011 Link to this post

    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. 
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 29 Nov 2011 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Michael Malone
    Michael Malone avatar
    68 posts
    Member since:
    May 2010

    Posted 29 Nov 2011 Link to this post

    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".
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 30 Nov 2011 Link to this post

    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.
  6. Michael Malone
    Michael Malone avatar
    68 posts
    Member since:
    May 2010

    Posted 30 Nov 2011 Link to this post

    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.
  7. Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 01 Dec 2011 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017