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

5 posts, 1 answers
  1. Graeme Mc
    Graeme Mc avatar
    17 posts
    Member since:
    Aug 2009

    Posted 12 Mar 2010 Link to this post

    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?

  2. robertw102
    robertw102 avatar
    265 posts
    Member since:
    Jul 2007

    Posted 13 Mar 2010 Link to this post

    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.
  3. Graeme Mc
    Graeme Mc avatar
    17 posts
    Member since:
    Aug 2009

    Posted 15 Mar 2010 Link to this post

    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?

  4. Answer
    Iana Tsolova
    Iana Tsolova avatar
    3388 posts

    Posted 18 Mar 2010 Link to this post

    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,
    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.
  5. Graeme Mc
    Graeme Mc avatar
    17 posts
    Member since:
    Aug 2009

    Posted 18 Mar 2010 Link to this post

    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) 


Back to Top