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

4 posts, 0 answers
  1. Jared Westlund
    Jared Westlund avatar
    1 posts
    Member since:
    Jul 2008

    Posted 06 Aug 2008 Link to this post

    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:

    1 <%@ Page Language="C#" AutoEventWireup="true"  %> 
    2 <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> 
    3  
    4 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
    5 <html xmlns="http://www.w3.org/1999/xhtml">  
    6 <head runat="server">  
    7     <style type="text/css">HTML { font-size: 10pt; font-family: Arial; }</style> 
    8 </head> 
    9 <body> 
    10     <form id="form1" runat="server">  
    11         <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
    12         <div> 
    13           
    14           
    15             <telerik:RadTreeView ID="myTree" OnClientNodeChecked="NodeWasChecked" CheckBoxes="true" runat="server">  
    16                 <Nodes> 
    17                     <telerik:RadTreeNode Text="Node A"></telerik:RadTreeNode> 
    18                     <telerik:RadTreeNode Text="Node B"></telerik:RadTreeNode> 
    19                     <telerik:RadTreeNode Text="Node C"></telerik:RadTreeNode> 
    20                     <telerik:RadTreeNode Text="Node D"></telerik:RadTreeNode> 
    21                     <telerik:RadTreeNode Text="Node E"></telerik:RadTreeNode> 
    22                 </Nodes> 
    23             </telerik:RadTreeView> 
    24             <input type="button" value="run repro" onclick="runRepro()" /> (checks every other node)  
    25               
    26               
    27             <script language="javascript" type="text/javascript">                  
    28                 function runRepro()  
    29                 {  
    30                     var tree = $find('<%= myTree.ClientID %>');                      
    31                     var nodes = tree.get_nodes();  
    32                     for (var i=0; i<nodes.get_count(); i++)  
    33                         if ((i%2)==0) { nodes.getNode(i).check(); }  
    34                 }  
    35                 function NodeWasChecked(sender, args)  
    36                 {  
    37                     var text = document.createTextNode("Function was called:  NodeWasChecked() - " + (new Date()).toString());                      
    38                     if (ResultsDiv.childNodes.length > 0)  
    39                     {  
    40                         ResultsDiv.insertBefore(document.createElement("br"), ResultsDiv.childNodes.item(0));                     
    41                         ResultsDiv.insertBefore(text, ResultsDiv.childNodes.item(0));  
    42                     }    
    43                     else  
    44                     {                          
    45                         ResultsDiv.appendChild(text);                          
    46                     }  
    47                 }          
    48             </script> 
    49         </div> 
    50           
    51           
    52         <div style="border:1px solid red; margin-top: 50px;">  
    53             <b>Expected Result:</b>  clicking the button will not check nodes, but not raise the OnClientNodeChecked() event.  
    54             however, manually clicking the checkboxes will raise this event and   
    55             <br /><br /> 
    56             <b>OnClientNodeChecked() Results:</b> 
    57             <div id="ResultsDiv" style="font-size:8pt;"></div> 
    58         </div> 
    59           
    60           
    61     </form>      
    62 </body> 
    63 </html> 
    64  
  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 07 Aug 2008 Link to this post

    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.
  3. Peichung
    Peichung avatar
    37 posts
    Member since:
    Aug 2008

    Posted 12 Nov 2009 Link to this post

    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,
  4. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 17 Nov 2009 Link to this post

    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.
Back to Top