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

OnClientNodeChecked event not called

3 Answers 64 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Vikas
Top achievements
Rank 1
Vikas asked on 26 Aug 2010, 01:55 PM
My OnClientNodeChecked event code (Javascript Code) between

trackChanges and commitChanges are not get executed

if i am having server side event onnodecheck

I am trying to simulate checkboxes as radio buttons. and uncheking the previous selected checkbox from JS. but it is not uncheking previous checkboxes.

3 Answers, 1 is accepted

Sort by
0
Cori
Top achievements
Rank 2
answered on 26 Aug 2010, 02:16 PM
Hello Vikas,

Can you show us the javascript code your using in your OnClientNodeChecked event? That way we can tell you what's wrong.
0
Vikas
Top achievements
Rank 1
answered on 26 Aug 2010, 03:00 PM

 

<telerik:RadCodeBlock runat="server" ID="RadCodeBlock1">

 

 

<script type="text/javascript">

 

 

// TreeView JS Code

 

 

// Author Vikas Agarwal

 

 

// Dated 26/8/2010

 

 

 

//<![CDATA[

 

 

var oldNode;

 

 

var treeView;

 

 

function pageLoad() {

 

treeView = $find(

"<%= RadTreeNotifications.ClientID %>");

 

}

// It will uncheck Parent Tree node if all the elements of the node are unchecked.

 

function uncheckParentIfNoChildNodeSelected(node) {

 

 

if (node != null) {

 

 

var level = node.get_level();

 

 

if (level == 1) {

 

 

 

var parentNode = node.get_parent();

 

 

var ChildList = parentNode.get_nodes();

 

 

if (ChildList != null) {

 

 

var ChildLength = ChildList.get_count();

 

 

if (ChildLength == 0)

 

 

return false;

 

 

for (var iLoop = 0; iLoop < ChildLength; iLoop++) {

 

 

var ChildItem = ChildList.getItem(iLoop);

 

 

if (ChildItem.get_checked() == true)

 

 

return false;

 

}

treeView.trackChanges();

parentNode.uncheck();

treeView.trackChanges();

}

}

}

}

 

 

// This function will be called on Each Node check changed

 

 

// It handles following condition

 

 

// To work checkboxes like radio buttons at root level

 

 

// if child node is selected, parent node should be selected by itself

 

 

// if parent node is selected then all the child nodes will be selcted

 

 

function onNodeChecked(sender, args) {

 

 

if (args != null) {

 

 

var node = args.get_node();

 

 

if (node != null) {

 

treeView.trackChanges();

 

 

// If user unchecks the same node of level 0 then do nothing

 

 

var level = node.get_level();

 

 

 

var oldParentNodeIndex = -1;

 

 

if (oldNode != null)

 

oldParentNodeIndex = getParentNodeIndex(oldNode);

 

var NewParentNodeIndex = getParentNodeIndex(node);

 

 

 

 

if (oldParentNodeIndex != NewParentNodeIndex) {

 

 

if (oldParentNodeIndex != -1) {

 

 

var parentNode = getParentNode0Level(oldNode);

 

uncheckAllChildNodes(parentNode);

parentNode.uncheck();

oldNode.uncheck();

}

node.toggle();

oldNode = node;

}

 

else {

 

node.toggle();

}

 

if (level != 0) {

 

 

var parentNode = getParentNode0Level(node);

 

 

if (parentNode.get_checked() == false) {

 

 

// Set Parent Node checked while checking other node check state

 

treeView._checkChildNodes =

false;

 

parentNode.set_checked(

true);

 

treeView._checkChildNodes =

true;

 

}

}

treeView.commitChanges();

 

uncheckParentIfNoChildNodeSelected(node);

 

}

}

}

// It uncheck all child nodes(If selected) of a node

 

function uncheckAllChildNodes(node) {

 

 

if (node != null) {

 

 

var ChildList = node.get_nodes();

 

 

if (ChildList != null) {

 

 

var ChildLength = ChildList.get_count();

 

 

for (var iLoop = 0; iLoop < ChildLength; iLoop++) {

 

 

var ChildItem = ChildList.getItem(iLoop);

 

 

if (ChildItem.get_checked() == true)

 

ChildItem.uncheck();

}

}

 

}

}

// It returns the parent Node at level 0 of any Node

 

function getParentNode0Level(node) {

 

 

if (node != null) {

 

 

if (node.get_level() == 0)

 

 

return node;

 

 

else

 

 

return getParentNode0Level(node.get_parent());

 

}

 

else

 

 

return null;

 

}

 

// It returns the parent node index of the node at level 0

 

 

function getParentNodeIndex(node) {

 

 

if (node != null) {

 

 

if (node.get_level() == 0)

 

 

return node.get_index();

 

 

else

 

 

return getParentNodeIndex(node.get_parent());

 

}

 

else

 

 

return -1;

 

 

}

 

//]]>

 

</

 

script>

 

</

 

telerik:RadCodeBlock>

 




It perfectly works if you are not having any nodecheck server side event
0
Yana
Telerik team
answered on 27 Aug 2010, 10:13 AM
Hello Vikas,

You should place the code inside RadScriptBlock instead of RadCodeBlock. Could you please change this and let us know how it goes?

Best wishes,
Yana
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
Tags
TreeView
Asked by
Vikas
Top achievements
Rank 1
Answers by
Cori
Top achievements
Rank 2
Vikas
Top achievements
Rank 1
Yana
Telerik team
Share this question
or