Hello,
I'm trying to maintain the state of my RadTreeView in my master page as i navigate from content page to content page. I have everything working except for the face that when I collapse my nodes and switch pages they open back up when I change content pages. I know its because I'm using clientside for my TreeNodeExpandMode, but if I switch it to ServerSideCallBack once the post back is completed even though the nodes say Expanded="True" I get a '+' sign and it loads on demand again. I just have two hyperlinks on my page that switch from Page1.aspx and Page2.aspx. Page1/2.aspx both use Site1.Master as their master page. Any suggestions would be great! Thank you.
Here is my master page code:
public partial class Site1 : System.Web.UI.MasterPage |
{ |
protected void Page_Load(object sender, EventArgs e) |
{ |
if (!Page.IsPostBack && String.IsNullOrEmpty((string)Session["treeViewState"])) |
{ |
LoadRootNodes(); |
Session["treeViewState"] = RadTreeView1.GetXml(); |
} |
else if (!String.IsNullOrEmpty((string)Session["treeViewState"])) |
{ |
this.RadTreeView1.LoadXml((string)Session["treeViewState"]); |
} |
} |
private void LoadRootNodes() |
{ |
for (int i = 0; i < 5; i++) |
{ |
this.RadTreeView1.Nodes.Add(new RadTreeNode() |
{ |
Text = String.Format("Root: {0}", i.ToString()), |
Value = i.ToString(), |
ExpandMode = TreeNodeExpandMode.ServerSideCallBack |
}); |
} |
} |
private void AddChildNodes(RadTreeNode node) |
{ |
for (int i = 0; i < 3; i++) |
{ |
node.Nodes.Add(new RadTreeNode() |
{ |
Text = String.Format("{0}{1}",node.Level.ToString(), i.ToString()), |
Value = String.Format("{0}{1}",node.Level.ToString(), i.ToString()), |
ExpandMode = TreeNodeExpandMode.ServerSideCallBack |
}); |
} |
} |
protected void RadTreeView1_NodeExpand(object sender, RadTreeNodeEventArgs e) |
{ |
AddChildNodes(e.Node); |
string treeViewState = (string)Session["treeViewState"]; |
RadTreeView cachedTreeView = new RadTreeView(); |
cachedTreeView.LoadXmlString(treeViewState); |
RadTreeNode cachedNodeClicked = cachedTreeView.FindNodeByValue(e.Node.Value); |
AddChildNodes(cachedNodeClicked); |
cachedNodeClicked.ExpandMode = TreeNodeExpandMode.ClientSide; |
cachedNodeClicked.Expanded = true; |
Session["treeViewState"] = cachedTreeView.GetXml(); |
} |
} |