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

Nodes lose value property after Databind

3 Answers 107 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Paul Robertson
Top achievements
Rank 1
Paul Robertson asked on 21 Dec 2012, 08:43 PM
Hi there

I have a server-side button handler to make changes to the database from which the RadTreeView is populated. However, after calling Databind on the tree object to reflect the changes, the node objects for the tree all lose their Value property, which is a bit of a difficulty as I need to make use of that Value in the client-side processing immediately after the postback. Is this behaviour by design, and if so, how can I refresh the property in question, to populate the Values for each node after the databind?

Thanks if you can help.

Regards

3 Answers, 1 is accepted

Sort by
0
Kevin
Top achievements
Rank 2
answered on 22 Dec 2012, 04:23 PM
Hello Paul,

How are you binding the RadTreeView? Are you using a DataSource control or just setting the DataSource property?
0
Paul Robertson
Top achievements
Rank 1
answered on 28 Dec 2012, 03:33 PM
Hi there

The life cycle for the code relevant to the problem is as follows:

1. In the initial server side Load handler, regardless of postback or not, an instance of a custom Hierarchical datasource object is created, and used to configure the Datasource property for a databind.

     cdsPubCommentDataSource = New CommentDataSource(1)
     radCommentTreeView1.DataSource = cdsPubCommentDataSource
     radCommentTreeView1.DataFieldID = "ID"
     radCommentTreeView1.DataFieldParentID = "ParentID"
     radCommentTreeView1.DataTextField = "Content"
     radCommentTreeView1.DataBind()


2. At the client, the treeview is populated correctly, and each node of the treeview can be seen to be represented as its own client-side Javascript object with a Value attribute with corresponding 'identity' value.

3. The user clicks on a button within the template of a node to run some client-side status processing which finally triggers a server-side button handler postback.

4. In the server-side click handler that modifies the underlying database, the server-side treeview node objects each have a correctly populated Value property, until the moment at which the databind method is called:

     mytreeview.DataBind()

at which point the content of each node is refreshed to correctly reflect the database changes, but the Value property is now empty (showing as an empty string "" during debugging), in all subsequent server-side processing ...

5. As the client is processing the response from the postback, the attempt to run findNodeByValue is unsuccessful, because each client-side node object is missing its 'value' attribute, as to be expected given the disappearance of the corresponding server-side Value (in step 4.)

i.e.,
     var node = tree.findNodeByValue(value);
returns 'null', as although a new client-side object exists for the node, it is lacking a 'value' attribute, and so the identity stored in the value attribute cannot be found.

Could anybody point me in the right direction for why this might be happening? Thanks very much!

0
Paul Robertson
Top achievements
Rank 1
answered on 02 Jan 2013, 06:19 PM
I think the answer to this problem is my misunderstanding of the Value property, which apparently is not natively populated at any stage in the radTreeView life cycle. Please correct me if I am wrong in my conclusion, but it seems that if the Value property is to be used client-side, it must be explicitly populated by assigning a string value on a node-specific basis to [mynode].Value during the server-side DataBound handler. This is the only way I can find to ensure that the Javascript tree object used by the client-side findNodeByValue function contains the required 'value' attribute - i.e., it is best to use this 'value' in the same way as a custom attribute, albeit one for which Telerik have provided a dedicated search function in the client-side API.

Tags
TreeView
Asked by
Paul Robertson
Top achievements
Rank 1
Answers by
Kevin
Top achievements
Rank 2
Paul Robertson
Top achievements
Rank 1
Share this question
or