Stop OnClientNodeClicked when double clicking?

4 posts, 1 answers
  1. Zonk
    Zonk avatar
    2 posts
    Member since:
    Dec 2011

    Posted 06 Dec 2011 Link to this post

    As in the topic - I have both events subscribed and I want to prevent NodeClick from happening when double click occurs, how can I do that?
  2. Answer
    Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 06 Dec 2011 Link to this post

    Hello Zonk,

    The issue with handling both events is that the OnClientNodeClicked event occurs before the OnClientDoubleClick.  The only way I can you handling this issue would be to delay the code being executed in the OnClientNodeClicked event and then stopping the code from executing in the OnClientDoubleClick event (if it occurs). So something like this:

    var delayedClickEvent;
      
    function OnClientNodeClicked(sender, args) {
        //  Store variables you need from event to be used in the delay click method
        delayedClickEvent = setTimeout('PerformDelayedClick()',500);
    }
    function OnClientDoubleClick(sender, args) {
        clearTimeout(delayedClickEvent);
          
        // Double Click Code
    }
    function PerformDelayedClick() {
        // Delayed Click Code
    }

    So in the OnClientNodeClicked event you create a timeout to perform the click event and hold a reference to the timeout. In the OnClientDoubleClick you clear the timeout, so the code doesn't execute, and perform any logic that needs to be done.

    I hope that helps.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Zonk
    Zonk avatar
    2 posts
    Member since:
    Dec 2011

    Posted 06 Dec 2011 Link to this post

    Thanks Kevin for solution!
  5. Bozhidar
    Admin
    Bozhidar avatar
    1103 posts

    Posted 06 Dec 2011 Link to this post

    Hello Kevin,

    Just one addition - sometimes depending on the browser and the delay time, a single click will occur twice. To prevent that you can add the followin line in the OnClientNodeClicked event, before you set the timeout:

    if (delayedClickEvent) clearTimeout(delayedClickEvent);

    You can read more about the subject here.Kind regards,
    Bozhidar
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top