416.467.9100 | Dundas Data Visualization | Login
Welcome Guest
Dashboard v5.0

This site makes extensive use of JavaScript.

Please enable JavaScript in your web browser and reload the page before proceeding.

Passing Parameters from a ASP.NET Application to your Dashboard

Hide navigation
RSS
Modified on Mon, 27 Jan 2014 04:27 PM Categorized as Level-Expert, Level-Intermediate, Samples
Dundas Dashboard Script LibraryPrevious


Overview

There will be times when you want to initialize a dashboard embedded in your webpage with a set of parameters based on a web form or through a URL query string (e.g. http://mydashboard/Mypage.aspx?username=John). In this article, we will show you how to pass parameters from your webpage to a dashboard that is integrated in your webpage through a form above the dashboard. The dashboard will be embedded in a ASP.NET application (which is then included in your webpage).

Tip: For more details on embedding the Dashboard Viewer in your ASP.NET application, see Using the Enhanced Viewer in ASP.NET Applications.

Also included at the end of this article in the Download section is a backup of the Dundas Dashboard data store (v2.5.1) and a sample project of the steps described in this article with full source code.

Dashboard with a form above for passing parameters.

Dashboard with a form above for passing parameters.


Requirements

Make sure the following prerequisites are installed on your computer:


Setting up the initParams in the Web application

To pass parameters from your ASP.NET application to the dashboard, you will first need to add your parameters to the ParameterInfoCollection object. From here you will call the GetLinkUri method (passing the ParameterInfoCollection object you created) to output an encoded parameter string which will be appended to the initParams property on your webpage (defined in the .aspx markup page) as such:

... ...


Below is the code as it appears in the code-behind that will take values submitted by the user through either a form post or a url and then append it to the initParams.

protected void Page_Load(object sender, EventArgs e) { ...

// Build the init params using the loginToken this.InitParams = string.Format("ddAppLoaderModule=1,Dd_ContentType=Dashboard,ServerUri={0},dwLoginToken={1},Dd_ContentId={2},dwDeleteOtherSessions={3},Dd_ViewerFeatures={4}", this.ServerUri, loginToken, this.DashboardContentId, deleteOtherSessions ? 1 : 0, viewerFeatures);

... //Grab Parameters InitializeParameters(); }

// /// Initializes the parameters. /// private void InitializeParameters() { ... if (paramInfoColl.Count > 0) { //Generate a URI which includes the user parameters set. //The GetLinkUri returns the following Data as a Uri, each segment separated by a "&": //0 - ServerUri with Dd_ContentId i.e. http://localhost:2501/?Dd_ContentId=445b5d7a-1e8b-403b-b11e-daa7f71b2aa5 //1 - Dd_ContentType //2 - Dd_ViewerFeatures //3 - Dd_Parameters: The user parameters, encoded Uri uriParams = IntegrationHelper.GetLinkUri(ServerUri, this.DashboardContentId, ViewerContentItemType.Dashboard, paramInfoColl); //Splits the above output to isolate and utilize the user parameters set. string[] uriSeg = uriParams.Query.Split('&'); //Adds the Dd_Parameters to the initial parameters sent to Dundas Dashboard, to load the desired Dashboard using the Parameters set by the user on the ASP.NET page. this.InitParams = this.InitParams + "," + uriSeg[3]; } }


Note: The ellipsis (...) means unrelated code not shown. Refer to the sample in the Download section for full code. For example, there is more code in the InitializeParameter method which populates the paramInfoColi with your parameters, which will be covered in the next section of this article.

Processing parameters in the ASP.NET application

The sample in this article will pass several different parameter types as they appear on the Dashboard:

  • Instant dimension (paramUsername)
  • Full time dimension (paramVisitDate)
  • Full categorical hierarchy dimension (paramUSA)

Single instant dimension filters

This method allows you to set parameter on an instant dimension parameter (e.g. a list of names). The example in the project will use this for setting the parameter on a dropdown of usernames.

This is the most simplest form of passing a parameter to an instant dimension filter.

/// /// Adds the single value parameter. /// /// The param info coll. /// Name of the param. /// The param values. private void AddSingleValueParameter(ParameterInfoCollection paramInfoColl, string paramName, params object[] paramValues) { // Create the parameter ParameterInfo paramInfo = new ParameterInfo { ParameterName = paramName };

// Create a filter value for the parameter DashboardFilterValueData fvd = new DashboardFilterValueData { SingleValue = paramValues[0] };

// Add filter value data to filter values paramInfo.FilterValues.Add(fvd);

// Add parameter to collection paramInfoColl.Add(paramInfo); }


Below is an example of the method call:

private void InitializeParameters() { // Extract the user passed parameters string userName = this.userNameDropDownList.SelectedValue;

ParameterInfoCollection paramInfoColl = new ParameterInfoCollection();

if (!string.IsNullOrEmpty(userName)) { this.AddSingleValueParameter(paramInfoColl, "paramUsername", userName); }

... }


Single instant dimension filter in the sample dashboard. Passed via the userName parameter.

Single instant dimension filter in the sample dashboard. Passed via the userName parameter.


Full time dimension (using dates and tokens)

This method allows you to set a parameter on an full time dimension parameter using either actual dates or using tokens (e.g. Beginning of current month).

The example in the project will use this for setting the parameter on a date range selector:

/// /// Adds the date range parameter. /// /// The param info coll. /// Name of the param. /// The param values. private void AddDateTimeParameter(ParameterInfoCollection paramInfoColl, string paramName, params object[] paramValues) { // Create the parameter ParameterInfo paramInfo = new ParameterInfo { ParameterName = paramName };

// Date values...

// As strings string startDateValue = paramValues[0].ToString(); string endDateValue = paramValues[1].ToString();

// As real datetimes DateTime startDate = DateTime.MinValue; DateTime endDate = DateTime.MinValue;

// As tokens NamedToken startDateToken = NamedToken.None; NamedToken endDateToken = NamedToken.None;

// Create a filter value for the parameter DashboardFilterValueData fvd = new DashboardFilterValueData { IsRange = true, IsConsolidatedDateTime = true };

// Get the start date as a token. On failure to parse, get it as a DateTime if (!Enum.TryParse(startDateValue, out startDateToken)) { DateTime.TryParse(startDateValue, out startDate); }

// Get the end date as a token. On failure to parse, get it as a DateTime if (!Enum.TryParse(endDateValue, out endDateToken)) { DateTime.TryParse(endDateValue, out endDate); }

// Build the member value data from start date/token DashboardMemberValueData mvdStartDate = new DashboardMemberValueData(); if (startDateToken != NamedToken.None) { mvdStartDate.NamedTokenValue = startDateToken; } else { mvdStartDate.Values.Add(startDate); } fvd.MemberValues.Add(mvdStartDate);

// Build the member value data from end date/token DashboardMemberValueData mvdEndDate = new DashboardMemberValueData(); if (endDateToken != NamedToken.None) { mvdEndDate.NamedTokenValue = endDateToken; } else { mvdEndDate.Values.Add(endDate); } fvd.MemberValues.Add(mvdEndDate);

// Add filter value data to filter values paramInfo.FilterValues.Add(fvd);

// Add parameter to collection paramInfoColl.Add(paramInfo); }


Below is an example of calling the method:

private void InitializeParameters() { // Extract the user passed parameters string startDate = this.startDateTextBox.Text; string endDate = this.endDateTextBox.Text;

//Use tokens if the use date tokens checkbox is checked if (this.useDateTokensCheckBox.Checked) { startDate = this.startDateTokenDropDownList.SelectedValue; endDate = this.endDateTokenDropDownList.SelectedValue; }

ParameterInfoCollection paramInfoColl = new ParameterInfoCollection();

if (!string.IsNullOrEmpty(startDate) && !string.IsNullOrEmpty(endDate)) { this.AddDateTimeParameter(paramInfoColl, "paramVisitDate", startDate, endDate); }

... }


Full time dimension dimension filter in the sample dashboard. Passed via the paramVisitDate parameter.

Full time dimension dimension filter in the sample dashboard. Passed via the paramVisitDate parameter.


Full categorical hierarchy dimension

This method allows you to set a parameter on a full categorical hierarchy dimension parameter. This code only demonstrates how to work with the filter values and member values to set up the parameters. Much of this will depend on how your hierarchy is setup.

The example in the project will use this for setting the parameter on a categorical parameter.

/// /// Adds the full categorical hierarchy parameter. /// /// The param info coll. /// Name of the param. /// The param values. private void AddFullCategoricalHierarchyParameter(ParameterInfoCollection paramInfoColl, string paramName, params object[] paramValues) { // Create the parameter ParameterInfo paramInfo = new ParameterInfo { ParameterName = paramName };

// Get the value string paramValue = paramValues[0].ToString();

if (paramValue == "Maine+Vermont+Connecticut") { this.AddSelectedMember("Connecticut", 2, paramInfo); this.AddSelectedMember("Maine", 2, paramInfo); this.AddSelectedMember("Vermont", 2, paramInfo); } else if (paramValue == "West+Midwest") { // West selection this.AddSelectedMember("West", 0, paramInfo); this.AddSelectedMember("Midwest", 0, paramInfo); }

// Add parameter to collection paramInfoColl.Add(paramInfo); }

private void AddSelectedMember(string member, int level, ParameterInfo paramInfo) { DashboardFilterValueData fvd = new DashboardFilterValueData(); DashboardMemberValueData mvd = new DashboardMemberValueData { HierarchyLevel = level }; mvd.Values.Add(member); fvd.MemberValues.Add(mvd);

// Add filter values to parameter paramInfo.FilterValues.Add(fvd); }



Below is an example of calling the method:

private void InitializeParameters() { // Extract the user passed parameters string usa = this.usaDropDownList.SelectedValue;;

ParameterInfoCollection paramInfoColl = new ParameterInfoCollection();

if (!string.IsNullOrEmpty(usa)) { this.AddFullCategoricalHierarchyParameter(paramInfoColl, "paramUSA", usa); }

... }


Full categorical hierarchy dimension filter in the sample dashboard. Passed via the paramUSA parameter.

Full categorical hierarchy dimension filter in the sample dashboard. Passed via the paramUSA parameter.


The USA hierarchy is defined with three levels:

  • Region (Key: Region)
  • Division (Key: Region, Division)
  • State (Key: State)

Based on the keys assigned per level, when you are setting up the DashboardFilterValueData and MemberValueData in code, you will have to take into account the values being added as it conforms to the hierarchy keys.

The USA hierarchy definition.

The USA hierarchy definition.


Download

PassingParametersSample.zip - Dundas Dashboard 2.5.1 DataStore SQL 2008 database backup and Visual Studio 2010 viewer integration sample solution.

Notes

  • The sample SQL 2008 database backup is provided as is without support for how they should be restored.

  • Use the username admin and password 1234 to log into the DataStore. Or use the Project Manager to import the project into your own data store database.


  • You will need to remove references to the Server.Integration.dll and Extensibility.Server.dll assemblies, and then re-add them using the assemblies from your Dundas Dashboard instance.

Related topics

  Name Size
- PassingParametersSample.zip 0 B

About Dundas | Contact Us Follow us on Twitter! | Privacy Statement | Report Site Issues

Copyright © 2009-2014 Dundas Data Visualization, Inc.