RadDatePicker SelectedDate from codebehind does not populate RadDateInput

4 posts, 0 answers
  1. Michael
    Michael avatar
    6 posts
    Member since:
    Aug 2012

    Posted 01 Jul 2008 Link to this post

    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.
    1     protected void rcbDateRange_SelectedIndexChanged(object sender, EventArgs e) 
    2     { 
    3         //Dates should be disabled unless Custom has been selected 
    4         RadDatePickerStart.Enabled = false
    5         RadDatePickerEnd.Enabled = false
    6  
    7         switch (rcbDateRange.SelectedValue) 
    8         { 
    9             case "WeekSun"
    10                 RadDatePickerStart.SelectedDate = DateTime.Today.AddDays(-5); 
    11                 RadDatePickerEnd.SelectedDate = DateTime.Today.AddDays(-1); 
    12                 break
    13             case "custom"
    14                 RadDatePickerStart.SelectedDate = DateTime.Today.AddDays(-1); 
    15                 RadDatePickerEnd.SelectedDate = DateTime.Today.AddDays(-1); 
    16                 RadDatePickerStart.Enabled = true
    17                 RadDatePickerEnd.Enabled = true
    18                 break
    19             default
    20                 RadDatePickerStart.SelectedDate = DateTime.Today.AddDays(-1); 
    21                 RadDatePickerEnd.SelectedDate = DateTime.Today.AddDays(-1); 
    22                 break
    23         } 
    24     } 

    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 
  2. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 04 Jul 2008 Link to this post

    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
  3. Chris Owens
    Chris Owens avatar
    12 posts
    Member since:
    May 2004

    Posted 06 May 2011 Link to this post

    Was this ever fixed, it's repeating in 2011.1
  4. Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 06 May 2011 Link to this post

    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.

Back to Top