Sending Parameters from js+html client to Server

In order to create and pass parameter from javascript to the server side you can use the following code, but bear in mind that this parameter should not match report Parameter names. It’s a kind of fake parameter which we will use for filtering purposes (and it should have unique name, in order to prevent parameters name collision):
var parameterExists = false;

        var parameters = reportViewer.parameters;

        if (parameters!=null)

        {

            for (var i = 0; i < parameters.length; i++) {

                if (reportViewer.parameters[i].Name == 'DataSetFilterSurname') {

                    reportViewer.parameters[i].Value = 'Fishman';

                    parameterExists = true;

                }

            }

           

        }

        if (!parameterExists)

        {

            var parameter = new PerpetuumSoft.Reporting.WebViewer.Model.ParameterModel();

            parameter.Name = 'DataSetFilterSurname';

            parameter.Type = 'System.String';

    parameter.DefaultValue = '';

            parameter.Value = '"Krukov"';

            if (reportViewer.parameters == null)

            {

                reportViewer.parameters = new PerpetuumSoft.Reporting.WebViewer.Model.ReportParametersModel();

            }

            reportViewer.parameters.add(parameter);

        }

 

On the server side we now have this parameter and can use it in order to filter data:

 

protected override void OnLoadData(IDictionary<string, object> parameters, string reportName, PerpetuumSoft.Reporting.Components.ReportSlot reportSlot)

        {           

            base.OnLoadData(parameters, reportName, reportSlot);

                      

            DataRow dataRow = dataTable1.NewRow();

            if (parameters["DataSetFilterSurname"].ToString() == "Rembrant")

            {

                dataRow["Surname"] = "Rembrant";

                dataRow["Age"] = 29;

                dataTable1.Rows.Add(dataRow);

            }

            if (parameters["DataSetFilterSurname"].ToString() == "Sholohov")

            {

                dataRow = dataTable1.NewRow();

                dataRow["Surname"] = "Sholohov";

                dataRow["Age"] = 22;

                dataTable1.Rows.Add(dataRow);

            }

            if (parameters["DataSetFilterSurname"].ToString() == "Kerjakov")

            {

                dataRow = dataTable1.NewRow();

                dataRow["Surname"] = "Kerjakov";

                dataRow["Age"] = 33;

                dataTable1.Rows.Add(dataRow);

            }

        }
Example demonstrates how to pass parameter and server side just retrieves this parameter. Filtering code doesn't make any sense and doesn't mean that such approach can take place in a real world examples.

You can find sample here:
http://perpetuumsoft.com/Support/SSR.MVC/SharpShooterMVC4Sample.zip

Add Feedback