Checking nodes quickly (double click) does not register correctly

4 posts, 0 answers
  1. Adam
    Adam avatar
    177 posts
    Member since:
    Oct 2012

    Posted 23 Sep 2011 Link to this post

    I've got a treeview with checkable nodes. I'm trying to keep a count of how many are checked and I'm using the OnClientNodeChecking call to do so. Here is my function:

    function UpdateTotal(sender, eventArgs) {
                var node = eventArgs.get_node();
                var pnode = node.get_parent();
     
                var attribs = pnode.get_attributes();
                var cnt = attribs.getAttribute("Count");
                 
                if (!node.get_checked()) {
                    cnt++;
                } else {
                    cnt--;
                }
                attribs.setAttribute("Count", cnt);
    //            var cnodes = pnode.get_nodes();
    //            var cnt = 0;
    //            for (var i = 0; i < cnodes.get_count(); i++) {
    //                if (cnodes.getNode(i).get_checked()) {
    //                    cnt++;
    //                }
    //            }
     
               pnode.set_text(attribs.getAttribute("DefaultName") + ' (' + cnt + ')');
            }

    However, I noticed when I click the checkbox quickly, the event does not get called and therefore the counts are incorrect. Here is a video displaying the issue.

    http://screencast.com/t/1FkFLNDk6

    You'll notice when the screen first loads, the count is correct. If I click the checkbox, the count changes correctly. But if I double-click a checkbox, the count is not longer in sync. When the box is checked, it shows 4, when it's unchecked it shows 5, but it should be the other way around. I've also noticed that when I do a postback and check the state of the node in the code behind, it does not reflect what is being on the screen. Basically, the number that you see next to the parent node correctly corresponds to the number of nodes the treeview believes are checked when it gets to the code behind. However, what is displayed does not match with what the treeview actually thinks is checked.

    Hopefully that makes sense,
    Adam
  2. Plamen
    Admin
    Plamen avatar
    2734 posts

    Posted 29 Sep 2011 Link to this post

    Hi Adam,

    It seems that quick clicking is making the javascript count wrong. You can try doing this logic or just some validation on the server.

    Greetings,
    Plamen Zdravkov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Adam
    Adam avatar
    177 posts
    Member since:
    Oct 2012

    Posted 29 Sep 2011 Link to this post

    Yes, the count is wrong, BUT more importantly, the count correctly reflects how many nodes the treeview thinks are checked when a postback occurs. So if I double click the node, and the count says 4 and it should say 3, when I do a postback and look at the checked nodes, I will get 4 checked nodes back, even though when you look at the screen there are only 3 checked.

    Doing validation on the server won't help things in this case, because I can't validate against what the screen says if the treeview itself doesn't match the on-screen treeview in a postback.
  5. Plamen
    Admin
    Plamen avatar
    2734 posts

    Posted 03 Oct 2011 Link to this post

    Hello Adam,

    We inspected the issue once again and it looks like a known behaviour in IE in executing the scripts simultaneously. In Chrome and in FireFox it was working as expected.

    I am sending the last code that we tested.

    If you have further questions please feel free to ask.


    Regards,
    Plamen Zdravkov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top