Hi.
I am not good at English.
I use RadTreeView for Ajax 2009 Q3.
I try to maintain a state of RadTreeView Nodes before creating a new folder via right-clicking menu.
The sorce code is the following.
namespace TelerikTreeView |
{ |
public partial class _Default : System.Web.UI.Page |
{ |
/// <summary> |
/// Variable for state maintein |
/// </summary> |
private RadTreeNodeCollection preChangeTreeNodes; |
protected void RadTreeView1_ContextMenuItemClick(object sender, RadTreeViewContextMenuEventArgs e) |
{ |
RadTreeNode clickedNode = e.Node; |
// Copy Nodes |
this.CopyRadTreeNodesTo(out preChangeTreeNodes); |
..... |
} |
/// <summary> |
/// The state of present TreeView is copied onto the RadTreeNodeCollection object of the argument. |
/// </summary> |
/// <param name="nodes"></param> |
private void CopyRadTreeNodesTo(out RadTreeNodeCollection nodes) |
{ |
nodes = new RadTreeNodeCollection(this.RadTreeView1); |
foreach (RadTreeNode node in this.RadTreeView1.Nodes) |
{ |
nodes.Add(node.Clone()); |
} |
} |
The following error occurs by the second post backing.
-----------------------
Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.
-----------------------
The error will not occurs when EnableViewState property of TreeView is false.
But I don't want to change EnableViewState to false. Beause I can not get RadTreeViewContextMenuEventArgs Value when it is false.
Also SessionState mode is SQLServer, I can not use session to maintain the node.
How to keep the node during page post-back?