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

Stop OnClientNodeClicked when double clicking?

3 Answers 64 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Zonk
Top achievements
Rank 1
Zonk asked on 06 Dec 2011, 12:52 PM
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?

3 Answers, 1 is accepted

Sort by
0
Accepted
Kevin
Top achievements
Rank 2
answered on 06 Dec 2011, 02:15 PM
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.
0
Zonk
Top achievements
Rank 1
answered on 06 Dec 2011, 02:41 PM
Thanks Kevin for solution!
0
Bozhidar
Telerik team
answered on 06 Dec 2011, 04:37 PM
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
Tags
TreeView
Asked by
Zonk
Top achievements
Rank 1
Answers by
Kevin
Top achievements
Rank 2
Zonk
Top achievements
Rank 1
Bozhidar
Telerik team
Share this question
or