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

Checking nodes quickly (double click) does not register correctly

3 Answers 56 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 23 Sep 2011, 06:41 PM
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

3 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 29 Sep 2011, 09:34 AM
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
0
Adam
Top achievements
Rank 1
answered on 29 Sep 2011, 11:58 AM
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.
0
Plamen
Telerik team
answered on 03 Oct 2011, 04:30 PM
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
Tags
TreeView
Asked by
Adam
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Adam
Top achievements
Rank 1
Share this question
or