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

OnClientNodeChecked doesn't get raised after programmatic node.check()

3 Answers 106 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Jared Westlund
Top achievements
Rank 1
Jared Westlund asked on 06 Aug 2008, 10:21 PM
This seems to be a bug in the control, since wouldn't this be a valid scenario?

My OnClientNodeChecked event gets fired in response to user click/check/uncheck.    But when I programmatically call the check() method of the client-side node, the same event does not get raised.

Here's a repro page:

<%@ Page Language="C#" AutoEventWireup="true"  %> 
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml">  
<head runat="server">  
    <style type="text/css">HTML { font-size: 10pt; font-family: Arial; }</style> 
</head> 
<body> 
    <form id="form1" runat="server">  
        <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
        <div> 
          
          
            <telerik:RadTreeView ID="myTree" OnClientNodeChecked="NodeWasChecked" CheckBoxes="true" runat="server">  
                <Nodes> 
                    <telerik:RadTreeNode Text="Node A"></telerik:RadTreeNode> 
                    <telerik:RadTreeNode Text="Node B"></telerik:RadTreeNode> 
                    <telerik:RadTreeNode Text="Node C"></telerik:RadTreeNode> 
                    <telerik:RadTreeNode Text="Node D"></telerik:RadTreeNode> 
                    <telerik:RadTreeNode Text="Node E"></telerik:RadTreeNode> 
                </Nodes> 
            </telerik:RadTreeView> 
            <input type="button" value="run repro" onclick="runRepro()" /> (checks every other node)  
              
              
            <script language="javascript" type="text/javascript">                  
                function runRepro()  
                {  
                    var tree = $find('<%= myTree.ClientID %>');                      
                    var nodes = tree.get_nodes();  
                    for (var i=0; i<nodes.get_count(); i++)  
                        if ((i%2)==0) { nodes.getNode(i).check(); }  
                }  
                function NodeWasChecked(sender, args)  
                {  
                    var text = document.createTextNode("Function was called:  NodeWasChecked() - " + (new Date()).toString());                      
                    if (ResultsDiv.childNodes.length > 0)  
                    {  
                        ResultsDiv.insertBefore(document.createElement("br"), ResultsDiv.childNodes.item(0));                     
                        ResultsDiv.insertBefore(text, ResultsDiv.childNodes.item(0));  
                    }    
                    else  
                    {                          
                        ResultsDiv.appendChild(text);                          
                    }  
                }          
            </script> 
        </div> 
          
          
        <div style="border:1px solid red; margin-top: 50px;">  
            <b>Expected Result:</b>  clicking the button will not check nodes, but not raise the OnClientNodeChecked() event.  
            however, manually clicking the checkboxes will raise this event and   
            <br /><br /> 
            <b>OnClientNodeChecked() Results:</b> 
            <div id="ResultsDiv" style="font-size:8pt;"></div> 
        </div> 
          
          
    </form>      
</body> 
</html> 
 

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 07 Aug 2008, 07:25 AM
Hi Jared Westlund,

nodeChecked is fired only upon user interaction. Calling the check method will not invoke that. Here is why:
consider calling the check method fired both nodeChecking and nodeChecked. Then it is possible that the implementation of nodeChecking cancels the check operation. As a result the developer would end up with unchecked node despite having called "check()". I recommend you extract the code of the nodecheck event handler in a separate method and call it immediately after you call the check method.

Regards,
Albert
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Peichung
Top achievements
Rank 1
answered on 12 Nov 2009, 05:28 PM
I have the same problem.  I am wondering if there is a way to raise server-side OnNodeCheck event manually right after I call node.check() ?

Thanks,
0
Veselin Vasilev
Telerik team
answered on 17 Nov 2009, 03:07 PM
Hello Peichung,

Here is a sample that will work:

<telerik:radtreeview runat="server" ID="t" CheckBoxes="true"
    onnodecheck="t_NodeCheck">
    <Nodes>
        <telerik:RadTreeNode Text="aaa"></telerik:RadTreeNode>
    </Nodes>
</telerik:radtreeview>
 
<input type="button" value="check" onclick="check()" />
 
<script type="text/javascript">
    function check() {
        var tree = $find("t");
        var node = tree.get_nodes().getNode(0);
        if (!node.get_checked()) {
            node.check();
            var command = { commandName: "Check", index: node._getHierarchicalIndex() };
            tree._postback(command);
        }
    }
</script>


Regards,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
TreeView
Asked by
Jared Westlund
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Peichung
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Share this question
or