Tuesday, January 20, 2009

While editing an ultrawebtree node, stop users to input escape characters

In order to stop users, from giving input of escape characters, you have to handle the editkeydown client side event. in the designer file inside the client side events add this:

EditKeyDown="UltraWebTree1_EditKeyDown"

In the javascript file add this function:

function UltraWebTree1_EditKeyDown(treeId, nodeId, keycode) {
if (keycode == 220) {
var treeInstance = igtree_getTreeById(UltraWebTreeClientID)
treeInstance.endEdit(false);
}
}

when the user presses "\" then the value of keycode becomes 220. endEdit(false) ends the editing process of a node, and goes back to the text that was there before editing began. endEdit(true) stops the editing but keeps the updated text that was while the tree node was being edited. So, its always a good idea to use endEdit(false) method. UltraWebTreeClientID was passed from the server side.

If you need to block user from pressing other keys too, then debug the process and get the value of keycode for corresponding characters, then add those values in the if condition.

No comments: