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

Determine change in state of checkbox

7 Answers 139 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Polaris431
Top achievements
Rank 1
Polaris431 asked on 28 Dec 2009, 01:35 PM
What is the simplist way to determine whether the checkbox for a node has changed its state. Currently I use Javascript code to store changes in a variable and send the contents of that variable back to the server. I suppose what I am looking for is something like a "CheckboxChanged" property. It really shouldn't have to be necessary for me to write additional code to keep track of these changes. It should be built into the Treeview control. In typical scenarios, when a user checks or unchecks something, this will often result in having to add or delete something on the server. Without recording the state, I would have to first get what already exists on the server and compare it to the current treeview state and either add or remove stuff.

7 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 28 Dec 2009, 02:03 PM
Hello,

I suggest you use OnClientNodeChecked client-side event or NodeCheck server-side event of RadTreeView.

Best regards,
Yana
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.
0
Polaris431
Top achievements
Rank 1
answered on 28 Dec 2009, 03:06 PM
Hi Yana,

I already am using those events. That's not what I was asking. I already indicated that I am writing Javascript code to handle the state between client and server. I was looking for a built-in way from the control to handle this for me.

Johann
0
Yana
Telerik team
answered on 28 Dec 2009, 03:19 PM
Hello Johann,

I'm sorry I didn't understand the question right.

You can use ClientChanges property of RadTreeView to access the client changes after postback.

Greetings,
Yana
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.
0
Polaris431
Top achievements
Rank 1
answered on 28 Dec 2009, 03:34 PM
Hi Yana,

Seems like we're getting close. However, it appears that using the ClientChanges object is only available on the server-side. Does this not mean that I must persist the entire treeview? At the moment, I have the treeview's EnableViewState set to "false" for performance reasons. I then use the AjaxManager to send changes in the treeview back to the server. Therefore, I don't believe the ClientChanges will be of any value. I just upgraded my RadControls from Q1 to the Q3 version. Is there anything in the Q3 version that allows me to persist the state of the treeview and then use ClientChanges?

Thanks
Johann
0
Polaris431
Top achievements
Rank 1
answered on 28 Dec 2009, 03:46 PM
Hi Yana,

I even tried setting the EnableViewState of the treeview to "true". I then changed the checkbox state on a node and did a postback. The ClientChanges object contained no changes. It does not appear that changing the "Checked" property on the client-side has any effect on ClientChanges.

Johann
0
Polaris431
Top achievements
Rank 1
answered on 28 Dec 2009, 04:05 PM
My mistake. If EnableViewState is set to true, it will detect changes to any attributes on the client side. I was forgetting to use trackChanges and commitChanges. However, it will not detect changes to properties. Changing the state of the checkbox results in the "Checked" property being changed but ClientChanges does not indicate this.
0
Dimitar Milushev
Telerik team
answered on 29 Dec 2009, 02:30 PM
Hello,

You are right, the ClientChanges does not contain this info. Please excuse us for misleading you.

The simplest way I think would be to use the Node's Attributes collection and handle the OnClientNodeChecked event. The in the nodeChecked handler you can do this:

function nodeChecked(sender, args)
{
    var node = args.get_node();
    var newState = node.get_attributes().getAttribute("newState");
     
    treeView.trackChanges();
     
    if(!newState) {
        // Original state hasn't be changed before so we record the new state
        if (node.get_checked())
            node.get_attributes().setAttribute("newState", "checked");
        else
            node.get_attributes().setAttribute("newState", "unchecked");
    }
    else {
        // We are reverting to our original state, clear the attribute
        node.get_attributes().setAttribute("newState", "");
    }
     
    treeView.commitChanges();
}

When you postback, on the server-side the "newState" Attribute will be set to checked/unchecked only if the state of the checkbox is different from the original. No matter how many times you click the checkbox, if you leave it in the original state when you postback, the Attribute will be an empty string.

I hope this helps.

Kind regards,
Dimitar Milushev
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
Polaris431
Top achievements
Rank 1
Answers by
Yana
Telerik team
Polaris431
Top achievements
Rank 1
Dimitar Milushev
Telerik team
Share this question
or