Skip to main content
A newer version of this page is available. .

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

Event Data

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

Property Description
DashboardId Gets the identifier of the loaded dashboard.
DashboardXml Get the XML document containing the definition of the loaded dashboard.
InitialState Gets or sets the initial state of the loaded dashboard.

Remarks

Use the SetInitialDashboardStateEventArgs.InitialState event parameter to specify the initial dashboard state. To learn more about a dashboard state, see Manage Dashboard State.

Note

The SetInitialDashboardState event is not raised if the ASPxDashboard control uses the DashboardConfigurator API.

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;
} 

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;
        }
    }
}

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

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;
            }
        }
    }
}
See Also