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

rad datetime picker

4 Answers 73 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Tiaan
Top achievements
Rank 1
Tiaan asked on 26 Mar 2014, 06:46 AM
Good day

I have a rad datetime picker on a asp website

I have to create the control dynamically.
I added an event handler to the control, but  the event is not firing at all.

Also i added an ID to the control which is not showing when i try and find that control trough firefox debugger.

 RadDateTimePicker dt = new RadDateTimePicker();
                    dt.SelectedDateChanged += new Telerik.Web.UI.Calendar.SelectedDateChangedEventHandler(dt_SelectedDateChanged);
                    dt.ID = "datetimepicker007";
                    Cell.Controls.Add(dt);


   void dt_SelectedDateChanged(object sender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e)
        {
          //  throw new NotImplementedException();
            Response.Redirect("www.google.com");
        }

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 26 Mar 2014, 07:21 AM
Hi Tiaan,

In order to fire the SelectedDateChanged event of RadDateTimePicker please try to set the AutoPostBackControl property of RadDateTiemPicker. This property indicates whether a postback to the server will occur when the user changes the time or date selection. This is useful when you would like to trigger form submit on date/time selection individually or for both controls. Please add the following C# code which works fine at my end.

C#:
dt.AutoPostBackControl = Telerik.Web.UI.Calendar.AutoPostBackControl.Calendar;

Thanks,
Shinu.
0
Tiaan
Top achievements
Rank 1
answered on 27 Mar 2014, 10:31 AM
Good day

The eventhandler control worked.
But now i have a much bigger problem . My page is dynamically created in page init, this occurs before the actual method for selecteddatechanged.
So when it enters init, it created the picker again, and when it comes to the datechanged method, its blank.
0
Shinu
Top achievements
Rank 2
answered on 28 Mar 2014, 03:52 AM
Hi Tiaan,

Please have a look into the sample code snippet which works fine at my end.

C#:
protected void Page_Init(object sender, EventArgs e)
{
    RadDateTimePicker dt = new RadDateTimePicker();
    dt.ID = "DatePicker1";
    dt.AutoPostBackControl = Telerik.Web.UI.Calendar.AutoPostBackControl.Calendar;
    dt.SelectedDateChanged += new Telerik.Web.UI.Calendar.SelectedDateChangedEventHandler(dt_SelectedDateChanged);
    form1.Controls.Add(dt);
}
void dt_SelectedDateChanged(object sender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e)
{
   //your code
}

Let me know if you have any concern.
Thanks,
Shinu.
0
Tiaan
Top achievements
Rank 1
answered on 28 Mar 2014, 05:54 AM
Hi

I found a fix for my bug. Unfortunately your code wouldn't work as i need to dynamically create the picker in code under a few if statements that can only be seen in that scope. I initially thought that the creation method needed to be under page init, The init method clears all data, But when i moved it to page load, the data was held.

Something interesting to read up on :-)

Thank you for your input
Tags
Calendar
Asked by
Tiaan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Tiaan
Top achievements
Rank 1
Share this question
or