aspnet-4267-components-tree-list-examples-how-to-save-and-restore-the-aspxtreelists-layout.md
This example shows how to save/restore the ASPxTreeList’s layout to/from a data store.
protected void ASPxTreeList1_ClientLayout(object sender,
DevExpress.Web.ASPxClientLayoutArgs e) {
if (e.LayoutMode == DevExpress.Web.ClientLayoutMode.Saving) {
SaveUserLayoutToDatabase(userID, "AccountTreeList", e.LayoutData);
}
else {
if (System.IO.File.Exists(fileName))
e.LayoutData = RestoreUserLayoutFromDatabase(userID, "AccountTreeList");
}
}
Protected Sub ASPxTreeList1_ClientLayout(sender As Object, _
e As DevExpress.Web.ASPxClientLayoutArgs)
If e.LayoutMode = DevExpress.Web.ClientLayoutMode.Saving Then
SaveUserLayoutToDatabase(userID, "AccountTreeList", e.LayoutData)
Else
If File.Exists(fileName) Then
e.LayoutData = RestoreUserLayoutFromDatabase(userID, "AccountTreeList")
End If
End If
End Sub
This example shows how to manually save and restore the previously saved layout. When the Save Layout or Load Layout button is clicked, the tree list’s client ASPxClientTreeList.PerformCallback method is used to send a callback to the server. This generates the server-side ASPxTreeList.CustomCallback event, which is handled to save or restore the tree list’s layout.
protected void ASPxTreeList1_CustomCallback(object sender,
DevExpress.Web.ASPxTreeList.TreeListCustomCallbackEventArgs e) {
if (e.Parameters == "save") {
SaveUserLayoutToDatabase("userID", "TreeListLayout", ASPxTreeList1.SaveClientLayout());
}
if (e.Parameters == "load") {
ASPxTreeList1.LoadClientLayout(GetUserLayoutFromDatabase("userID", "TreeListLayout"));
}
}
Protected Sub ASPxTreeList1_CustomCallback(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxTreeList.TreeListCustomCallbackEventArgs)
If e.Parameters = "save" Then
SaveUserLayoutToDatabase("userID", "TreeListLayout", ASPxTreeList1.SaveClientLayout())
End If
If e.Parameters = "load" Then
ASPxTreeList1.LoadClientLayout(GetUserLayoutFromDatabase("userID", "TreeListLayout"))
End If
End Sub
Note
To specify which information on the ASPxTreeList layout can be saved, use options provided by the ASPxTreeList.SettingsCookies property.