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
Can you show us the javascript code your using in your OnClientNodeChecked event? That way we can tell you what's wrong.
<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
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