Why does the RadMonthYearPicker give me a day?

0 Answers 81 Views
MonthYearPicker
SSirica
Top achievements
Rank 3
Iron
Iron
Iron
SSirica asked on 21 Jun 2022, 06:53 PM

This isn't an actual problem, but more of a curiosity.  Why does something called the RadMonthYearPicker still render a full date and time?  I thought that's what the RadDatePicker was for?  It should just give me the Month and Year and no date...which is what it's name would lead you to believe is all that would be involved.  I'm not choosing June 1st 2022.  I'm choosing June 2022.  I understand that I can format the selected date...that's not the point. 

Things that make you go hummmmm. 

Rumen
Telerik team
commented on 22 Jun 2022, 11:59 AM

Are you able to reproduce the reported behavior in the following online demo: https://demos.telerik.com/aspnet-ajax/monthyearpicker/overview/defaultcs.aspx? 
SSirica
Top achievements
Rank 3
Iron
Iron
Iron
commented on 22 Jun 2022, 02:02 PM

I have no idea.  I noticed it when I stopped my code and looked at the available properties to see where I was going to pull my values from.  I happen to notice that when I chose June 2022 the SelectedDate was actually...#6/1/2022 12:00:00 AM#.  

Here's an analogy that I think would apply to this situation.  It's like a strainer and a bowl.  If I use a strainer I'm not expecting to get the liquid just the pasta.  If I wanted liquid I would just put my pasta in a bowl...no need for the strainer. 

I can get just the month or just the year.  It's just extra code.  It's not what I was expecting to have to do.  No big deal...like I said things that make you go hummmmmm.  

Rumen
Telerik team
commented on 23 Jun 2022, 07:29 AM | edited

I do see that the client-side get_selectedDate() method return the time too but it is 00:00:00 as shown in the example below

While the server SelectedDate property returns only the Date (Month and Day):

 

            <telerik:RadMonthYearPicker ID="RadMonthYearPicker1" runat="server" SelectedDate="2016/5/5 12:00">
                <DateInput runat="server" ></DateInput>
            </telerik:RadMonthYearPicker>
            <asp:Button Text="Get Date" OnClick="Unnamed_Click" runat="server" />
            <asp:TextBox runat="server"  ID="DateValue"/>

 

 

protected void Unnamed_Click(object sender, EventArgs e)
{
    DateValue.Text = RadMonthYearPicker1.SelectedDate;
}

Can you share the declaration of the control on your side? It could be something date input formatting or even Culture related - see https://docs.telerik.com/devtools/aspnet-ajax/controls/monthyearpicker/functionality/formatting-values?

 

 

 

SSirica
Top achievements
Rank 3
Iron
Iron
Iron
commented on 23 Jun 2022, 02:13 PM

Sure.  This is my html.  Very simple.

<telerik:RadMonthYearPicker ID="dpSrc" runat="server">
    <DateInput runat="server" Label="Anchor to Copy" Width="100%" DisplayDateFormat="yyyy/MM" />
</telerik:RadMonthYearPicker>

This is what it produces:

Rumen
Telerik team
commented on 24 Jun 2022, 09:22 AM | edited

I got it! I examined the source code and noticed that the object type of the SelectedDate property is DateTime so you are getting an expected result since DateTime object in C# always has the time, just set to the beginning of the day:

 

       /// <summary>
        /// Sets or returns the currently selected date. The default value is the value of
        /// <strong>System.DateTime.MinValue</strong>.
        /// </summary>
        /// <remarks>
        /// 	<para>Use the <b>SelectedDate</b> property to determine the selected date on the
        ///     <a href="RadCalendar~Telerik.Web.UI.RadCalendar.html">RadCalendar</a>
        ///     control.</para>
        /// 	<para>The <b>SelectedDate</b> property and the
        ///     <a href="RadCalendar~Telerik.Web.UI.RadCalendar~SelectedDates.html">SelectedDates</a>
        ///     collection are closely related. When the
        ///     <a href="RadCalendar~Telerik.Web.UI.RadCalendar~EnableMultiSelect.html">EnableMultiSelect</a>
        ///     property is set to <b>false</b>, a mode that allows only a single date selection,
        ///     <b>SelectedDate</b> and <b>SelectedDates[0]</b> have the same value and
        ///     <b>SelectedDates.Count</b> equals 1. When the <b>EnableMultiSelect</b> property is
        ///     set to <b>true</b>, mode that allows multiple date selections, <b>SelectedDate</b>
        ///     and <b>SelectedDates[0]</b> have the same value.</para>
        /// 	<para>The <b>SelectedDate</b> property is set using a System.DateTime
        ///     object.</para>
        /// 	<para>When the user selects a date on the <strong>RadCalendar</strong> control, the
        ///     <a href="RadCalendar~Telerik.Web.UI.RadCalendar~SelectionChanged_EV.html">SelectionChanged</a>
        ///     event is raised. The <b>SelectedDate</b> property is updated to the selected date.
        ///     The <b>SelectedDates</b> collection is also updated to contain just this
        ///     date.</para>
        /// 	<blockquote class="dtBlock">
        /// 		<b class="le">Note</b> Both the <b>SelectedDate</b> property and the
        ///         <b>SelectedDates</b> collection are updated before the <b>SelectionChanged</b>
        ///         event is raised. You can override the date selection by using the
        ///         <strong>OnSelectionChanged</strong> event handler to manually set the
        ///         <b>SelectedDate</b> property. The <b>SelectionChanged</b> event does not get
        ///         raised when this property is programmatically set.
        ///     </blockquote>
        /// </remarks>
        [Category("Dates Management")]
        [DatePickerBrowsable(false)]
        [SimplePersistenceSetting]
        public DateTime SelectedDate
        {
            get
            {
                if (this.SelectedDates.Count == 0)
                {
                    return DateTime.MinValue;
                }
                return this.SelectedDates[0].Date;
            }
            set
            {
                DateTime dateOnly = TruncateTimeComponent(value);
                if (dateOnly == DateTime.MinValue)
                {
                    this.SelectedDates.Clear();
                }
                else
                {
                    this.SelectedDates.SelectRange(dateOnly, dateOnly);
                }
            }
        }

 

No answers yet. Maybe you can help?

Tags
MonthYearPicker
Asked by
SSirica
Top achievements
Rank 3
Iron
Iron
Iron
Share this question
or