How can I abort node selection via ClientSide Object Model?
I was trying to do this in the
BeforeNodeSelectionChanged client event
var tree = igtree_getTreeById(treeId);tree.NeedPostBack = false;tree.CancelPostBack = true;
THis doesn't prevent the node from changing and it didn't prevent the postback from occuring.
What am I doing wrong?
I second the opinion that returning true to cancel an event is... let's just say surprising.
I post here the (6 hours worth of struggle) code that asks the user if they want to abandon changes and only if confirmed allows to change selection to another node. The itemmodified variable is set to true when editing starts and to false on save button click. The treeview contains this declaration :
<ClientSideEvents BeforeNodeSelectionChange="BeforeNodeSelChanged" NodeClick="TreeNodeClick" />
--- cut here ---
var itemmodified = false; var oldNode; var answer; function TreeNodeClick(treeId, nodeId, button) { var tree = igtree_getTreeById(treeId); if (!answer) { var node = tree.getNodeById(oldNode); node.setSelected(true); return true; } else { var node = tree.getNodeById(nodeId); node.setSelected(true); itemmodified = false; return false; } } function BeforeNodeSelChanged(treeId, nodeId, newNodeId) { if (newNodeId != oldNode) { answer = !itemmodified || confirm('Item not saved. Abandon changes ?'); if (answer) { oldNode = newNodeId; } else { oldNode = nodeId; } return true; } return false; }
Wow, in 100 years I probably woudn't of thought to return true to cancel the event. Thank you for the quick response, this fixed my problem.
Try
return true;
I am assuming the server side event you have handled is the NodeSelectionChanged event. If you have the NodeClicked event handled then you will have to do the same for the client side NodeClick event by returning true.