The sample illustrates how to save the current ASPxDashboard state (such as master filter or parameter values) to cookies on the client side and restore this state on the server side. The following API is used in this example:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="WebDashboard_DashboardStateCookies.Default" %>
<%@ Register Assembly="DevExpress.Dashboard.v17.1.Web, Version=17.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.DashboardWeb" TagPrefix="dx" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div style="position:absolute; left:0; right:0; top:0; bottom:0;">
<dx:ASPxDashboard ID="ASPxDashboard1" runat="server"
WorkingMode="ViewerOnly"
ClientInstanceName="webDashboard"
IncludeDashboardIdToUrl="True"
DashboardStorageFolder="~/App_Data/Dashboards"
Height="100%" Width="100%" OnSetInitialDashboardState="ASPxDashboard1_SetInitialDashboardState">
<ClientSideEvents DashboardStateChanged="
function(s, e) {
var cookies = e.DashboardState;
ASPxClientUtils.SetCookie('ASPxDashboardState', cookies);
}"></ClientSideEvents>
</dx:ASPxDashboard>
</div>
</form>
</body>
</html>
using DevExpress.DashboardCommon;
using DevExpress.DashboardWeb;
using System;
using System.Web;
namespace WebDashboard_DashboardStateCookies
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ASPxDashboard1_SetInitialDashboardState(object sender, SetInitialDashboardStateEventArgs e)
{
HttpCookie cookie = Request.Cookies["ASPxDashboardState"];
if (cookie != null)
{
DashboardState dashboardState = new DashboardState();
dashboardState.LoadFromJson(HttpUtility.UrlDecode(cookie.Value));
if (e.DashboardId == "dashboard1")
e.InitialState = dashboardState;
}
}
}
}
Imports DevExpress.DashboardCommon
Imports DevExpress.DashboardWeb
Imports System
Imports System.Web
Namespace WebDashboard_DashboardStateCookies
Partial Public Class [Default]
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Protected Sub ASPxDashboard1_SetInitialDashboardState(ByVal sender As Object, ByVal e As SetInitialDashboardStateEventArgs)
Dim cookie As HttpCookie = Request.Cookies("ASPxDashboardState")
If cookie IsNot Nothing Then
Dim dashboardState As New DashboardState()
dashboardState.LoadFromJson(HttpUtility.UrlDecode(cookie.Value))
If e.DashboardId = "dashboard1" Then
e.InitialState = dashboardState
End If
End If
End Sub
End Class
End Namespace
<%@ Page Language="vb" AutoEventWireup="true" CodeBehind="Default.aspx.vb"
Inherits="WebDashboard_DashboardStateCookies.Default" %>
<%@ Register Assembly="DevExpress.Dashboard.v17.1.Web, Version=17.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.DashboardWeb" TagPrefix="dx" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div style="position:absolute; left:0; right:0; top:0; bottom:0;">
<dx:ASPxDashboard ID="ASPxDashboard1" runat="server"
WorkingMode="ViewerOnly"
ClientInstanceName="webDashboard"
IncludeDashboardIdToUrl="True"
DashboardStorageFolder="~/App_Data/Dashboards"
Height="100%" Width="100%" OnSetInitialDashboardState="ASPxDashboard1_SetInitialDashboardState">
<ClientSideEvents DashboardStateChanged="
function(s, e) {
var cookies = e.DashboardState;
ASPxClientUtils.SetCookie('ASPxDashboardState', cookies);
}"></ClientSideEvents>
</dx:ASPxDashboard>
</div>
</form>
</body>
</html>