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

Setting the SelectedDate property of the RadDatePicker disables the SelectedDateChanged event handler?

4 Answers 1079 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Boris
Top achievements
Rank 1
Boris asked on 29 Jul 2014, 05:11 PM
I have a RadDateTimePicker on a page of my C# DotNet 4.0 web app.  
The idea is that every time the selected date changes, the event handler updates a text box. 
This is intended to be an Ajax event, not a full page postback.
To this end, the controls are set up in the RadAjaxManager as follows:

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" >      
        <AjaxSettings>            
            <telerik:AjaxSetting AjaxControlID="rdtDateTime">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="txtCount" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>        
    </telerik:RadAjaxManager>

This works perfectly, unless in the page load event I set the SelectedDate property of the RadDateTimePicker.
If I do that the SelectedDateChanged event stops firing. 

Suggestions?  

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 30 Jul 2014, 06:04 AM
Hi Boris,

Please have a look into the following code I tried which works fine at my end.

ASPX:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RLoadingPanel">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="rdtDateTime">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="txtCount" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="RLoadingPanel" runat="server" Skin="Web20">
</telerik:RadAjaxLoadingPanel>
<div>
    <telerik:RadDateTimePicker ID="rdtDateTime" runat="server" OnSelectedDateChanged="rdtDateTime_SelectedDateChanged"
        AutoPostBackControl="Both">
    </telerik:RadDateTimePicker>
    <telerik:RadTextBox ID="txtCount" runat="server">
    </telerik:RadTextBox>
</div>

C#:
protected void rdtDateTime_SelectedDateChanged(object sender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e)
{
    txtCount.Text = rdtDateTime.SelectedDate.ToString();
}

Please get back with your complete code if this doesn't help.

Thanks,
Princy.
0
Accepted
Princy
Top achievements
Rank 2
answered on 30 Jul 2014, 06:30 AM
Hi Boris,

I made some changes in the C# code and here is the updated code.

C#:
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        //Setting a date dyanamically during the page load.
        rdtDateTime.SelectedDate = DateTime.Now;
    }
}
protected void rdtDateTime_SelectedDateChanged(object sender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e)
{
    txtCount.Text = rdtDateTime.SelectedDate.ToString();
}

Thanks,
Princy.
0
Boris
Top achievements
Rank 1
answered on 30 Jul 2014, 01:02 PM
Painfully obvious now.  

The code to set the SelectedDate was in a function that needed to be called on all Page_Loads, not just !IsPostBack.

Thanks.
0
Accepted
Princy
Top achievements
Rank 2
answered on 31 Jul 2014, 06:17 AM
Hi Boris,

When you select a date from the RadDateTimePicker with AutoPostBackControl property set, the Page_Load event fires before the SelectedDateChanged event which is always expected.

So if you are setting the SelectedDate property in the Page_Load (outside the !IsPostBack), each time you select a date, the Page_Load will fire and the date you selected from the RadDateTimePicker UI gets overridden with the value you are setting in the page load event and as a result the same gets reflected in the SelectedDateChanged event as well. Hence the user have a feeling like the date selection is not working and setting the SelectedDate property directly in the Page_Load is not advisable.

Thanks,
Princy.
Tags
Calendar
Asked by
Boris
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Boris
Top achievements
Rank 1
Share this question
or