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

RadDatePicker SelectedDate from codebehind does not populate RadDateInput

3 Answers 645 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 01 Jul 2008, 09:16 PM
I am trying to understand why the RadDatePicker will not populate the Input field with just calling the following statement in the PreRender method?

    protected void RadDatePickerStart_PreRender(object sender, EventArgs e) 
    { 
        if (!RadDatePickerStart.SelectedDate.HasValue) 
        { 
            RadDatePickerStart.SelectedDate = DateTime.Today.AddDays(-1); 
        } 
    } 

For me to get the value to populate to the DatePicker textbox I have to add this assignment:
RadDatePickerStart.DateInput.SelectedDate = DateTime.Today.AddDays(-1); 

Can someone please explain why that is needed?

I have a RadComboBox and upon selection of its SelectedIndexChanged event method that works without even having to set the additional DateInput.SelectedDate as you can see in this little code snippet.
    protected void rcbDateRange_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        //Dates should be disabled unless Custom has been selected 
        RadDatePickerStart.Enabled = false
        RadDatePickerEnd.Enabled = false
 
        switch (rcbDateRange.SelectedValue) 
        { 
            case "WeekSun"
                RadDatePickerStart.SelectedDate = DateTime.Today.AddDays(-5); 
                RadDatePickerEnd.SelectedDate = DateTime.Today.AddDays(-1); 
                break
            case "custom"
                RadDatePickerStart.SelectedDate = DateTime.Today.AddDays(-1); 
                RadDatePickerEnd.SelectedDate = DateTime.Today.AddDays(-1); 
                RadDatePickerStart.Enabled = true
                RadDatePickerEnd.Enabled = true
                break
            default
                RadDatePickerStart.SelectedDate = DateTime.Today.AddDays(-1); 
                RadDatePickerEnd.SelectedDate = DateTime.Today.AddDays(-1); 
                break
        } 
    } 

I am not sure why you have to set the DateInput.SelectedDate in the PreRender to make it bubble up to the DatePicker's textbox.

I am using the SharedCalendar control and not sure if that makes a difference.

Just for completeness here is the aspx telerik elements:
                      <telerik:RadComboBox ID="rcbDateRange" AllowCustomText="false" Skin="WebBlue" OnSelectedIndexChanged="rcbDateRange_SelectedIndexChanged"  
                            AutoPostBack="true" runat="server">  
                            <Items>  
                                <telerik:RadComboBoxItem Text="Yesterday" Value="Yesterday" Selected="True" runat="server" />  
                                <telerik:RadComboBoxItem Text="Week To Date (Starts Sun)" Value="WeekSun" runat="Server" />  
                                <telerik:RadComboBoxItem Text="Week To Date (Starts Mon)" Value="WeekMon" runat="server" />  
                                <telerik:RadComboBoxItem Text="Prior Week (Sun-Sat)" Value="PriorSun" runat="server" />  
                                <telerik:RadComboBoxItem Text="Prior Week (Mon-Sun)" Value="PriorMon" runat="server" />  
                                <telerik:RadComboBoxItem Text="Month to Date" Value="MonthToDate" runat="server" />  
                                <telerik:RadComboBoxItem Text="Prior Month" Value="PriorMonth" runat="server" />  
                                <telerik:RadComboBoxItem Text="Quarter to Date" Value="QuarterToDate" runat="server" />  
                                <telerik:RadComboBoxItem Text="Prior Quarter" Value="PriorQuarter" runat="server" />  
                                <telerik:RadComboBoxItem Text="Year to Date" Value="YearToDate" runat="server" />  
                                <telerik:RadComboBoxItem Text="Prior Year" Value="PriorYear" runat="server" />  
                                <telerik:RadComboBoxItem IsSeparator="true" runat="server" />  
                                <telerik:RadComboBoxItem Text="Custom Range" Value="custom" runat="server" />  
                            </Items>  
                        </telerik:RadComboBox>  
  
                            <telerik:RadDatePicker ID="RadDatePickerStart" SharedCalendarID="sharedCalendar" OnPreRender="RadDatePickerStart_PreRender"  
                                Skin="WebBlue" Enabled="false" runat="server">  
                                <DateInput ID="rdpStartInput" ReadOnly="true" runat="server" />  
                            </telerik:RadDatePicker>  
  
                        <telerik:RadDatePicker ID="RadDatePickerEnd" SharedCalendarID="sharedCalendar" OnPreRender="RadDatePickerEnd_PreRender"  
                            Skin="WebBlue" Enabled="false" runat="server">  
                            <DateInput ID="rdpEndDateInput" ReadOnly="true" runat="server" />  
                        </telerik:RadDatePicker>  
 
 
        <telerik:RadCalendar ID="sharedCalendar" RangeMinDate="2005-04-01" runat="server" 
            EnableMultiSelect="false" Skin="WebBlue" Width="200px" ShowRowHeaders="false" 
            OnPreRender="sharedCalendar_PreRender" UseColumnHeadersAsSelectors="false"
        </telerik:RadCalendar 

3 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 04 Jul 2008, 02:11 PM
Hello Michael,

I tested your scenario and was able to replicate the described issue locally. It seems that this behaviour is a bug and the SelectedDate properly works in all handlers except in PreRender. I will forward this to our developers, for further researching and a fix will be available in some of the upcoming releases.

Thank you for bringing this to our attention.
As a token of gratitude for your feedback I have updated your Telerik points.

Greetings,
Maria Ilieva
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Chris Owens
Top achievements
Rank 1
answered on 06 May 2011, 07:56 AM
Was this ever fixed, it's repeating in 2011.1
0
Pavel
Telerik team
answered on 06 May 2011, 09:24 AM
Hello Chris,

I cannot reproduce the problem with our latest release. Could you provide more details about your scenario so we can investigate further?

Best wishes,
Pavel
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Calendar
Asked by
Michael
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Chris Owens
Top achievements
Rank 1
Pavel
Telerik team
Share this question
or