RadDateTimePicker - Showing/hiding TimeView

5 posts, 0 answers
  1. John Brownell
    John Brownell avatar
    26 posts
    Member since:
    Apr 2007

    Posted 04 Mar 2008 Link to this post

    I updated my calendar control to the Prometheus version and it broke some of the funtionality i was previously using. I will describe what I am trying to do and hopefully someone can let me know how I can implement this with the Prometheus controls or if this is in fact a bug.

    Previously, I was using a RadDateTimePicker control with a Checkbox control labeled "Enter time". I was setting the visibility of the TimeView part, and the format of the dateview part, using the status of the checkbox ... like this:

    bool enterTime = chkShowTimes.Checked;  
     
    RadDateTimePicker1.DateInput.DateFormat = enterTime ? "M/d/yyyy h:mm tt" : "d";  
    RadDateTimePicker1.DateInput.DisplayDateFormat = enterTime ? "M/d/yyyy h:mm tt" : "d";  
     
    RadDateTimePicker1.TimeView.Visible = enterTime;  
    RadDateTimePicker1.TimePopupButton.Visible = enterTime;  
     

    This concept worked in the non-Prometheus version, but now once I set the "TimeView" portion "visible = false", I get a javascript error:

    Microsoft JScript runtime error: Sys.InvalidOperationException:   
    Component 'RadDateTimePicker1_timeView' was not found. 

    And once this happens, the calendar button breaks and does not popup the calendar.

    Any ideas?

    Thanks,
    John
    Pyron Technologies
  2. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 07 Mar 2008 Link to this post

    Hello John,

    Hiding the control like this causes it not to render properly, and some of the resources may therefore not be found. Therefore, you can try a different approach to hide the items:

    .css
    <style type="text/css">  
     
    .class1  
    {  
    display:none;  
    }  
     
    .class2  
    {  
    display:block;  
    }  
     
    </style> 

    .cs
     protected void Page_Load(object sender, EventArgs e)  
        {  
            bool enterTime = chkShowTimes.Checked;  
     
            RadDateTimePicker1.DateInput.DateFormat = enterTime ? "M/d/yyyy h:mm tt" : "d";  
            RadDateTimePicker1.DateInput.DisplayDateFormat = enterTime ? "M/d/yyyy h:mm tt" : "d";  
     
            RadDateTimePicker1.TimeView.CssClass = enterTime ? "class1" : "class2";  
            RadDateTimePicker1.TimePopupButton.CssClass = enterTime ? "class1" : "class2";  
        } 

    I hope this suggestion helps.

    Best wishes,
    Yavor
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. James
    James avatar
    16 posts
    Member since:
    Dec 2011

    Posted 24 Jul 2013 Link to this post

    I realize this is an old post but I have a follow-up question.  I'm trying to replace a RadDatePicker control with a RadDateTimePicker control and selectively hide/show the time portion.  I followed Yavor's suggestion above and it works as expected, however, even though the clock icon is not displayed, it displays any selected dates followed by "12:00 AM".  For example, if I choose 7/23/2013 in the calendar popup, it shows "7/23/2013 12:00 AM" in the text area.  Both the DateFormat and DisplayDateFormat values are set to "d" which equates to "M/d/yyyy".  How can I also hide the "12:00 AM" from appearing along with the selected date?

    Thank you,

    James
  5. James
    James avatar
    16 posts
    Member since:
    Dec 2011

    Posted 24 Jul 2013 Link to this post

    I realize this is an old post but I have a follow-up question.  I'm trying to replace a RadDatePicker control with a RadDateTimePicker control and selectively hide/show the time portion.  I followed Yavor's suggestion above and it works as expected, however, even though the clock icon is not displayed, it displays any selected dates followed by "12:00 AM".  For example, if I choose 7/23/2013 in the calendar popup, it shows "7/23/2013 12:00 AM" in the text area.  Both the DateFormat and DisplayDateFormat values are set to "d" which equates to "M/d/yyyy".  How can I also hide the "12:00 AM" from appearing along with the selected date?

    Thank you,

    James
  6. A2H
    A2H avatar
    177 posts
    Member since:
    Mar 2010

    Posted 24 Jul 2013 Link to this post

    Hi James,

    A slight modification to the code will do the task here

    We are hiding the timeview when check box is checked but at the same time here we are assigning the date format  of  RadDateTimePicker1 as "M/d/yyyy h:mm tt” instead of “d”.

    When I change the condition check code its starting working fine.

    Please use the below code


    bool enterTime = CheckBox1.Checked;
     
            RadDateTimePicker1.DateInput.DateFormat = enterTime ? "d" : "M/d/yyyy h:mm tt";
            RadDateTimePicker1.DateInput.DisplayDateFormat = enterTime ? "d" : "M/d/yyyy h:mm tt";
             
            RadDateTimePicker1.TimeView.CssClass = enterTime ? "class1" : "class2";
            RadDateTimePicker1.TimePopupButton.CssClass = enterTime ? "class1" : "class2";

    Thanks,
    A2H
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017