Search code examples
javascriptreporting-servicesreportviewerweb-parts

Can you get parameter values of reportviewer at runtime?


I have a very specific question about the reporting services report viewer control.

I appreciate any help. I am a bit of a novice with Javascript on the client side, but I have to use this in my project.

THE REQUIREMENT

I need to retrieve the current value of a single parameter on a report viewer control embedded in a webpart at runtime. I need to access the value using Javascript on the client side.

Can this even be done? The reportviewer doesn't appear to get rendered.

THE HTML CODE FOR THE REPORT VIEWER

<asp:UpdatePanel ID="UpdatePanel1" runat="server" OnUnload="UpdatePanel_Unload">
    <ContentTemplate>
            <rsweb:ReportViewer ID="ReportViewer1" runat="server" 
            Font-Names="Verdana" Font-Size="8pt" Height="383px" 
            InteractiveDeviceInfos="(Collection)" ProcessingMode="Remote" 
            WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" Width="757px" 
            SizeToReportContent="True">
        </rsweb:ReportViewer>
    </ContentTemplate>
</asp:UpdatePanel>

Solution

  • UPDATE- WORKING CODE BELOW

    The key was creating a custom data attribute as @Fil indicated in this link (http://html5doctor.com/html5-custom-data-attributes/) and passing from the code behind and then accessing the $.cache. And passing the clientID of the reportviewer into the javascript function to get to the current instance of the webpart child controls.

    <input type="hidden" id="<%= ASP_SSRS.ClientID %>_myDataState" 
    onchange="compareUnitValues(this.id, this.parentNode.id, '<%= ReportViewer1.ClientID %>',  '<%= ASP_SSRS.ClientID %>', '<%= btnSendHiddenField.ClientID %>');" />
    
    <script type ="text/javascript">
    function compareUnitValues(elemt, parent, reportviewerID, value1, value2) {
      var myDataUnit = $("#" + elemt),
         parentObject = $("#" + parent),
         reportviewerObject = $("#" + reportviewerID),
         ssrs    = $("#" + value1),
         btnSend = $("#" + value2);
    
      var myDataUnitValue = myDataUnit.val();
      var myDataUnitJSON = jQuery.parseJSON(myDataUnitValue);
      var currentmyDataUnit = myDataUnitJSON.currentUnit.objectId;
      var sessioncurrentObjectId = document.getElementById('<%= hiddenCurrentObjectId.ClientID %>').value;
      ssrs.val(myDataUnitValue);
      var currentReportViewerParam = $("#" + reportviewerID).attr("data-report-param");
    
      if (currentmyDataUnit != currentReportViewerParam) {
      btnSend.trigger("click");
      }    
    

    }

    FROM CODE BEHIND CREATE THE CUSTOM DATA ATTRIBUTE
    ReportViewer1.Attributes.Add("data-report-param", parsedObjectId)