ASPxDashboard.SetInitialDashboardState Event
Allows you to specify the initial dashboard state when loading a dashboard.
Namespace: DevExpress.DashboardWeb
Assembly:
DevExpress.Dashboard.v21.2.Web.WebForms.dll
NuGet Package:
DevExpress.Web.Dashboard
Declaration
public event SetInitialDashboardStateEventHandler SetInitialDashboardState
Public Event SetInitialDashboardState As SetInitialDashboardStateEventHandler
Event Data
Use the SetInitialDashboardStateEventArgs.InitialState event parameter to specify the initial dashboard state. To learn more about a dashboard state, see Manage Dashboard State.
To clear states (unselect all values) of dashboard items in the SetInitialDashboardState event, assign an empty array of objects to the DashboardItemState.MasterFilterValues property:
protected void ASPxDashboard1_SetInitialDashboardState(object sender, SetInitialDashboardStateEventArgs e) {
var state = new DashboardState();
// ...
var itemState = new DashboardItemState("comboBoxDashboardItem");
itemState.MasterFilterValues.Add(new object() { });
state.Items.Add(itemState);
// ...
e.InitialState = state;
}
Protected Sub ASPxDashboard1_SetInitialDashboardState(ByVal sender As Object, ByVal e As SetInitialDashboardStateEventArgs)
Dim state As New DashboardState()
' ...
Dim itemState As New DashboardItemState("comboBoxDashboardItem")
itemState.MasterFilterValues.Add(New Object() { })
state.Items.Add(itemState)
' ...
e.InitialState = state
End Sub
Examples
The sample illustrates how to specify a dashboard state (such as master filter or parameter values) in code and how to apply this state when loading a dashboard for the first time. In this example, the DashboardState object holds the required dashboard state. The ASPxDashboard.SetInitialDashboardState
event is used to apply the specified dashboard state when loading a dashboard.
View Example: How to specify a default dashboard state in code
using DevExpress.DashboardCommon;
using DevExpress.DashboardWeb;
using System;
using System.Collections.Generic;
namespace WebDashboard_ManualDashboardState {
public partial class Default : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
}
protected void ASPxDashboard1_SetInitialDashboardState(object sender, SetInitialDashboardStateEventArgs e) {
e.InitialState = InitializeDashboardState();
}
public DashboardState InitializeDashboardState() {
DashboardState dashboardState = new DashboardState();
DashboardParameterState parameterState =
new DashboardParameterState("countryParameter", "USA", typeof(string));
DashboardItemState gridFilterState = new DashboardItemState("gridDashboardItem1");
gridFilterState.MasterFilterValues.AddRange(new List<object[]>() {
new string[1] { "Andrew Fuller" },
new string[1] { "Laura Callahan" }
}
);
DashboardItemState treemapDrilldownState = new DashboardItemState("treemapDashboardItem1");
treemapDrilldownState.DrillDownValues.Add("Beverages");
DashboardItemState rangeFilterState = new DashboardItemState("rangeFilterDashboardItem1");
rangeFilterState.RangeFilterState.Selection =
new RangeFilterSelection(new DateTime(2015, 1, 1), new DateTime(2016, 1, 1));
dashboardState.Parameters.Add(parameterState);
dashboardState.Items.AddRange(new List<DashboardItemState>() {
gridFilterState,
treemapDrilldownState,
rangeFilterState }
);
return dashboardState;
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="WebDashboard_ManualDashboardState.Default" %>
<%@ Register Assembly="DevExpress.Dashboard.v19.1.Web.WebForms, Version=19.1.15.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"
DashboardStorageFolder="~/App_Data/Dashboards"
WorkingMode="ViewerOnly"
Height="100%" Width="100%" OnSetInitialDashboardState="ASPxDashboard1_SetInitialDashboardState">
</dx:ASPxDashboard>
</div>
</form>
</body>
</html>
Imports DevExpress.DashboardCommon
Imports DevExpress.DashboardWeb
Imports System
Imports System.Collections.Generic
Namespace WebDashboard_ManualDashboardState
Public Partial Class [Default]
Inherits 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)
e.InitialState = InitializeDashboardState()
End Sub
Public Function InitializeDashboardState() As DashboardState
Dim dashboardState As DashboardState = New DashboardState()
Dim parameterState As DashboardParameterState = New DashboardParameterState("countryParameter", "USA", GetType(String))
Dim gridFilterState As DashboardItemState = New DashboardItemState("gridDashboardItem1")
gridFilterState.MasterFilterValues.AddRange(New List(Of Object())() From {New String(0) {"Andrew Fuller"}, New String(0) {"Laura Callahan"}})
Dim treemapDrilldownState As DashboardItemState = New DashboardItemState("treemapDashboardItem1")
treemapDrilldownState.DrillDownValues.Add("Beverages")
Dim rangeFilterState As DashboardItemState = New DashboardItemState("rangeFilterDashboardItem1")
rangeFilterState.RangeFilterState.Selection = New RangeFilterSelection(New DateTime(2015, 1, 1), New DateTime(2016, 1, 1))
dashboardState.Parameters.Add(parameterState)
dashboardState.Items.AddRange(New List(Of DashboardItemState)() From {gridFilterState, treemapDrilldownState, rangeFilterState})
Return dashboardState
End Function
End Class
End Namespace
<%@ Page Language="VB" AutoEventWireup="true" CodeBehind="Default.aspx.vb"
Inherits="WebDashboard_ManualDashboardState.Default" %>
<%@ Register Assembly="DevExpress.Dashboard.v19.1.Web.WebForms, Version=19.1.15.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"
DashboardStorageFolder="~/App_Data/Dashboards"
WorkingMode="ViewerOnly"
Height="100%" Width="100%" OnSetInitialDashboardState="ASPxDashboard1_SetInitialDashboardState">
</dx:ASPxDashboard>
</div>
</form>
</body>
</html>
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:
- The ASPxClientDashboard.DashboardStateChanged event is handled to obtain the current dashboard state.
- The ASPxClientUtils.SetCookie client-side method is used to save the dashboard state to cookies.
- In the
ASPxDashboard.SetInitialDashboardState
event handler, the dashboard state is loaded from the cookies and applied to a dashboard.
View Example: How to save a dashboard state to cookies
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="WebDashboard_DashboardStateCookies.Default" %>
<%@ Register Assembly="DevExpress.Dashboard.v19.1.Web.WebForms, Version=19.1.15.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;
}
}
}
}
<%@ Page Language="VB" AutoEventWireup="true" CodeBehind="Default.aspx.vb"
Inherits="WebDashboard_DashboardStateCookies.Default" %>
<%@ Register Assembly="DevExpress.Dashboard.v19.1.Web.WebForms, Version=19.1.15.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>
Imports DevExpress.DashboardCommon
Imports DevExpress.DashboardWeb
Imports System
Imports System.Web
Namespace WebDashboard_DashboardStateCookies
Public Partial Class [Default]
Inherits 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 DashboardState = New DashboardState()
dashboardState.LoadFromJson(HttpUtility.UrlDecode(cookie.Value))
If Equals(e.DashboardId, "dashboard1") Then e.InitialState = dashboardState
End If
End Sub
End Class
End Namespace
See Also