Skip to main content
Tab

ASPxTreeView.ClientLayout Event

Allows you to save and restore the previously saved layout of the ASPxTreeView.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v24.1.dll

NuGet Package: DevExpress.Web

Declaration

public event ASPxClientLayoutHandler ClientLayout

Event Data

The ClientLayout event's data class is ASPxClientLayoutArgs. The following properties provide information specific to this event:

Property Description
LayoutData Gets or sets the layout data.
LayoutMode Indicates whether a control’s layout should be saved or restored.

Remarks

Handle the ClientLayout event to save and restore the ASPxTreeView’s layout from a data store.

Save Layout
The event parameter’s LayoutMode property returns Saving. The LayoutData property contains the ASPxTreeView’s current layout that should be saved, for example, to a database.
Restore Layout
The LayoutMode property returns Loading. Read the ASPxTreeView’s layout data from a data store and assign it to the LayoutData property.

Example: How to store and restore an ASPxTreeView’s layout state

<dx:ASPxTreeView ID="virtualTree" runat="server" 
    OnVirtualModeCreateChildren="virtualTree_VirtualModeCreateChildren"
    OnClientLayout="virtualTree_ClientLayout" 
    OnExpandedChanging="virtualTree_ExpandedChanging" />
protected void virtualTree_VirtualModeCreateChildren(object source, TreeViewVirtualModeCreateChildrenEventArgs e) {
  List<TreeViewVirtualNode> children = new List<TreeViewVirtualNode>();

  if (e.NodeName == null) {
    AppendChildNode(children, "me", "Me!", false);
    AppendChildNode(children, "family", "Family", false);
    AppendChildNode(children, "friends", "Friends", false);
  }
  else {
    if (e.NodeName == "me") {
      AppendChildNode(children, "clean", "Cleaning");
      AppendChildNode(children, "drive", "Driving", false);
      AppendChildNode(children, "play", "Playing");             
    }           
    else if (e.NodeName == "family") {
      AppendChildNode(children, "anthony", "Anthony", false);
      AppendChildNode(children, "chris", "Chris");              
    }
    else if (e.NodeName == "friends") {
      AppendChildNode(children, "john", "John", false);
      AppendChildNode(children, "ram", "Ram");
    }
    else if (e.NodeName == "drive") {
      AppendChildNode(children, "crv", "CRV");
      AppendChildNode(children, "bmw", "BMW");
      AppendChildNode(children, "kluger", "Kluger");                
    }
    else if (e.NodeName == "anthony") {
      AppendChildNode(children, "run", "Running");
      AppendChildNode(children, "swim", "Swimming");                
    }
    else if (e.NodeName == "john") {
      AppendChildNode(children, "read", "Reading");
      AppendChildNode(children, "test", "Testing");
    }
  }
  e.Children = children;
}

protected void virtualTree_ClientLayout(object sender, ASPxClientLayoutArgs e) {
  if (e.LayoutMode == ClientLayoutMode.Loading) {
    if (Session["layout"] != null)
      e.LayoutData = Session["layout"].ToString();
  }
  else {
    Session["layout"] = e.LayoutData;
  }
}
private void AppendChildNode(IList<TreeViewVirtualNode> nodeList, string nodeName, string nodeText) {
  AppendChildNode(nodeList, nodeName, nodeText, true);
}
private void AppendChildNode(IList<TreeViewVirtualNode> nodeList, string nodeName, string nodeText, bool isLeaf) {
  TreeViewVirtualNode node = new TreeViewVirtualNode(nodeName, nodeText);
  node.IsLeaf = isLeaf;
  nodeList.Add(node);

}
protected void virtualTree_ExpandedChanging(object source, TreeViewNodeCancelEventArgs e) {

}
See Also