Pass dashboard parameters from viewer to a web application

Modified on Thu, 12 Jun 2014 09:57 AM by nikhilb@dundas.com — Categorized as: Level-Expert, Parameter Controls, Parameters, Samples, Viewer


Overview

This article shows how to retrieve and pass parameters from the embedded Dashboard Viewer to an ASP.NET web application by saving the parameters, per dashboard, per user while browsing.

Steps involve a function in the web page that takes a string and posts it it to the .aspx page using an AJAX call. This JavaScript function is called in the dashboard application using the services.EvalJavaScript at every parameter changed event. This call passes all the parameter values on the dashboard to the function on the webpage. The values can then be retrieved and stored in session using the Request and Session objects in the web application.

Once the parameters are retrieved, all the user choices can be remembered if they navigate away from the page and come back for as long as the sessions lasts. This is done using the sample on how to send parameters from ASP.NET application to a Dashboard.

Apart from saving the values to session, they can also be stored more permanently, by user name, so that it always remembers what the user was last looking at on any particular dashboard.

Steps


function sendParameters(parameterList) { request = new XMLHttpRequest(); request.open('POST', 'SaveParameters.aspx', true); request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); request.setRequestHeader("Connection", "close"); request.send('params=' + parameterList); }


string test = "dashboardId," + services.CurrentDashboard.DashboardId.ToString(); foreach (DashboardParameter p in services.CurrentDashboard.DashboardParameters) { test += "," + p.Name + "," + p.FilterValues0.MemberValues0.Values0.ToString(); } services.EvalJavaScript("sendParameters('" + test + "');");


if (Request"params" != null) { String dashboardParametersInput = Request"params"; String" title=" dashboardParameters = dashboardParametersInput.Split(new char">"> dashboardParameters = dashboardParametersInput.Split(new char[ { ',' }); Session"dashboardParameters" = dashboardParameters; }

if (Session"dashboardParameters" != null) { String">"> dashboardParameters = (String)Session["dashboardParameters"; for (int i = 0; i < dashboardParameters.Length; i += 2) { Response.Write(dashboardParametersi + ": " + dashboardParametersi + 1); Response.Write("
"); } }


Another way to store the parameters is to use the serializing and deserializing methods in the ParameterInfoCollection that works in both client (Silverlight and DundasScript) and server (.NET).



/***** Serialize *****/ ParameterInfoCollection parameters = new ParameterInfoCollection(); // Add parameters string parametersString = parameters.SerializeToString();

/***** Deserialize *****/ ParameterInfoCollection parameters = ParameterInfoCollection.Parse(parametersString);



Related Topics