0

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>
tomepenn
  • 93
  • 12
  • To do this you will need to use a script manager in your asp.net application since the parameters can change and do not post back to your app in your setup. You will need to use JavaScript to iterate the ReportViewer1's child elements and find the parameter control and extract the value. – Ross Bush Dec 22 '13 at 03:09
  • Thanks Irb. I have a script manager on there. The update panel, and related reportviewer is embedded in a webpart. Can I start at the webpart and work my way down the report viewer and child elemenets? – tomepenn Dec 22 '13 at 07:38
  • Does the webpart show up in the dom if you press f12 while running your app? – Ross Bush Dec 22 '13 at 15:35
  • Yes. The webpart, the update panel and the reportviewer are all in the DOM with the unique ID prefixes. How do I get to the paramater value of the reportviewer using this? – tomepenn Dec 23 '13 at 01:52
  • 1
    #WebPartctl00_m_g_9d6a6c3c_11d0_4e03_bbd2_b907172c437d #ctl00_m_g_9d6a6c3c_11d0_4e03_bbd2_b907172c437d_ctl01_UpdatePanel1 #ctl00_m_g_9d6a6c3c_11d0_4e03_bbd2_b907172c437d_ctl01_ReportViewer1 – tomepenn Dec 23 '13 at 01:53
  • 1
    asp.net gives you a client id value that resolves to the guid type id's you are seeing...you have to use the client id and a javascript function to find the $("# – Ross Bush Dec 24 '13 at 03:28
  • Thanks Irb. This is just what I need but I am struggling with the mechanics. Here is a some code I am using and my DOM on the next comment. var reportparamattribute = document.getElementById('<%= reportviewer1.ClientID %>').data("Report-Param"); – tomepenn Dec 24 '13 at 08:52
  • I have more than one instance of the reportviewer on separate tabs. ('ctl00_m_g_66e41117_8ff5_4650_bf4d_7a4a25e326f3_ctl01_ReportViewer1_ctl04').control.HideActiveDropDown();" data-report-param="1068" interactivedeviceinfos="(Collection)">
    – tomepenn Dec 24 '13 at 08:53

1 Answers1

0

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)
tomepenn
  • 93
  • 12