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

RadDateTimePicker - events not firing when javascript is added as an attribute

4 Answers 133 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Graeme Mc
Top achievements
Rank 1
Graeme Mc asked on 12 Mar 2010, 11:59 AM
I'm using a RadDateTimePicker on a dynamically loaded control, and javascript is used to track any changes made on each control.
So I've added the following code, which works for the editing of the textbox and when selecting from the timeview part of the control.
(I presume these controls are inheriting onchange and onclick events as they're not available with intellisense.)

this.rdtpAbsoluteBegin.DateInput.Attributes.Add("OnChange", String.Format("javascript:DesignChangeMade('{0}')", CompositeEntity.CompositeID.ToString())); 
this.rdtpAbsoluteBegin.TimeView.Attributes.Add("OnClick", String.Format("javascript:DesignChangeMade('{0}')", CompositeEntity.CompositeID.ToString())); 
 

However, when I apply this same code to the Calendar - no matter what event I use - the javascript is not firing.
I've tried things like OnChange, ClientEvents-OnDateClick, ClientEvents-OnDateSelected etc. both on the RadDateTimePicker itself and on the Calendar.

this.rdtpAbsoluteBegin.Calendar.Attributes.Add("OnClick", String.Format("javascript:DesignChangeMade('{0}')", CompositeEntity.CompositeID.ToString())); 

Is there something I'm missing, or could you suggest another way to do this?

Thanks,
Graeme

4 Answers, 1 is accepted

Sort by
0
robertw102
Top achievements
Rank 1
answered on 13 Mar 2010, 07:34 PM
You should use the ClientEvents exposed by the RadDateTimePicker and Calendar controls. It appears you said that you did that, but are setting them like this:

this.RadDateTimePicker.ClientEvents.OnDateClick = "javascript:SomeFunction(SomeValue)";

If so that is most likely the reason it doesn't work. You can't include the javascript keyword in the method call, as that is obviously used only in links, and you can't pass parameters to it. The correct way of setting the methods is like so:

this.RadDateTimePicker.ClientEvents.OnDateClick = "SomeFunction";

You can refer to the online help on the ClientEvents for the Calendar controls.


I hope that helps.
0
Graeme Mc
Top achievements
Rank 1
answered on 15 Mar 2010, 11:22 AM
Thanks for your reply.

The problem is that I'm using RadDateTimePicker on a dynamically loaded control, and the way it's been designed is to call a javascript function that is not directly accessible at this point. Therefore, I can't use your example and call a javascript function in the markup because the function I'm calling is already defined elsewhere. I.e: it's beyond my control but I have to set the javascript in the control's attribute, in code behind!

What I'm confused about is why it works for both DateInput and TimeView, but not for Calendar. I presume because of the way the controls are rendered in html, DateInput and TimeView have "onchange" and "onclick" events respectively (even though these events are not available in the markup). Would you be able to tell me what client events the Calendar has in it's rendered state?

0
Accepted
Iana Tsolova
Telerik team
answered on 18 Mar 2010, 08:19 AM
Hi Graeme,

To call the function you want in the OnDateClick client-side event handler of RadCalendar, you can try modifying your code as below:

RadDateTimePicker1.Calendar.ClientEvents.OnDateClick = "function(sender, eventArgs){MyFunction(args);}";

Note that RadCalendar renders as a table and the OnDateClick client-side event basically handles the click event of each cell of that table.

I hope this helps.

Kind regards,
Iana
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Graeme Mc
Top achievements
Rank 1
answered on 18 Mar 2010, 03:38 PM
That seems to work:

 this.rdtpAbsoluteEnd.Calendar.ClientEvents.OnDateClick = "function(sender, eventArgs){CalendarClicked('" + CompositeEntity.CompositeID.ToString() + "');}"
 

and then in the markup:
<script type="text/javascript"
    function CalendarClicked(ID) 
    { 
        DesignChangeMade(ID); 
    } 
</script> 

Thanks


Tags
Calendar
Asked by
Graeme Mc
Top achievements
Rank 1
Answers by
robertw102
Top achievements
Rank 1
Graeme Mc
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or