0

I could use some advice please.

THE SCENARIO

I have a tabbed control on the page.

There an update panel on each tab.

Inside each update panel is an instance of a custom Web part (asp.net)

I need to get the parameter value of the report viewer embedded in a user control in the Web part.

I need to retrieve this value using java script on the client side.

To be clear, I don't want to pass up variables using hidden controls or similar methods.

Can I reference the property of the bottom most object, a report viewer?

THE UPDATE PANEL CODE

                    <td><table border="0" cellpadding="0" cellspacing="0" width="100%">
                        <tr class="ms-WPHeader">
                            <td align="left" class="ms-wpTdSpace">&#160;</td><td title="Graduation Rates - My Visual WebPart" id="WebPartTitlectl00_m_g_08bc0677_b337_4b17_8729_6ca0b60b83e7" class="ms-WPHeaderTd"><h3 style="text-align:justify;" class="ms-standardheader ms-WPTitle"><nobr><span>Graduation Rates</span><span id="WebPartCaptionctl00_m_g_08bc0677_b337_4b17_8729_6ca0b60b83e7"></span></nobr></h3></td><td align="right" class="ms-WPHeaderTdMenu" onclick="OpenWebPartMenu(&#39;MSOMenu_WebPartMenu&#39;, this, &#39;WebPartctl00_m_g_08bc0677_b337_4b17_8729_6ca0b60b83e7&#39;,&#39;False&#39;); TrapMenuClick(event); return false;"><span style="display:none;"></span><div class="ms-WPMenuDiv" onmouseout="this.className='ms-WPMenuDiv'" onmouseover="this.className='ms-WPMenuDivHover'"><a onclick="OpenWebPartMenuFromLink(&#39;MSOMenu_WebPartMenu&#39;, this, &#39;WebPartctl00_m_g_08bc0677_b337_4b17_8729_6ca0b60b83e7&#39;,&#39;False&#39;); return false;" id="WebPartctl00_m_g_08bc0677_b337_4b17_8729_6ca0b60b83e7_MenuLink" onkeydown="WebPartMenuKeyboardClick(document.getElementById('WebPartctl00_m_g_08bc0677_b337_4b17_8729_6ca0b60b83e7_MenuLink'), 13, 40, event)" href="#" title="Graduation Rates Web Part Menu" class="ms-wpselectlink" onblur="UpdateWebPartMenuFocus(this, 'ms-wpselectlink', 'ms-WPEditText');" onfocus="UpdateWebPartMenuFocus(this, 'ms-wpselectlinkfocus', 'ms-WPEditTextVisible');" menuid="MSOMenu_WebPartMenu"><img class="ms-WPHeaderMenuImg" src="/_layouts/images/wpmenuarrow.png" alt="Graduation Rates Web Part Menu" style="border-width:0px;" /></a></div></td><td class="ms-WPHeaderTdSelection"><span class="ms-WPHeaderTdSelSpan"><input type="checkbox" id="SelectionCbxWebPartctl00_m_g_08bc0677_b337_4b17_8729_6ca0b60b83e7" class="ms-WPHeaderCbxHidden" title="Select or deselect Graduation Rates Web Part" onblur="this.className='ms-WPHeaderCbxHidden'" onfocus="this.className='ms-WPHeaderCbxVisible'" onkeyup="WpCbxKeyHandler(event);" onmouseup="WpCbxSelect(event); return false;" onclick="TrapMenuClick(event); return false;" /></span></td><td align="left" class="ms-wpTdSpace">&#160;</td>
                        </tr>

UPDATE- WORKING CODE BELOW

The key was creating a custom data attribute as @Fil indicated 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
  • 1
    What does it look like in renderd HTML? The part you need to access I mean. – Yuriy Galanter Dec 21 '13 at 01:23
  • 1
    The problem with this is that report viewer is a control in of it self, and the parameters you need are most likely are on server side and will never render to the client. They are used to init the control. What parameters do you need from the report viewer control? – Eugene S. Dec 21 '13 at 01:57
  • Thanks for answering guys. I added the html page output. – tomepenn Dec 21 '13 at 05:28
  • Eugene. I think you are right. I just need the current parameter that was set in the parameter propert in the code being using this code (working code). Dim paramObjectID As ReportParameter = New ReportParameter("ObjectID", parsedObjectId) ReportViewer1.ServerReport.SetParameters(paramObjectID) – tomepenn Dec 21 '13 at 05:29

1 Answers1

1

If you have that property visible when the html renders (see if it does by viewing source on your browser), then you would be able to fetch it on the client end using JS.

You could reference the report viewer control either by assigning it a unique class name, or by using jQuery's ends with or contains selector:

$("[id*='ReportViewer1']").attr("attributeName"); - this is the contains selector

http://api.jquery.com/attribute-contains-selector/

http://api.jquery.com/attribute-ends-with-selector/

Is this what you are looking for?

UPDATE on the HTML5 data attribute question:

Just a cleaner way to store arbitrary data in the html (for more convenient access to Javascript). Here is a good article that explains it here

So, what you would do in practice is this: Imagine you want to add the report viewer's parameter (which for the sake of argument has a value of "42") as an attribute to a Panel control you have with an ID="Panel1". In code behind you would do

Panel1.Attributes.Add("data-report-param", "42");.

Because the Panel control is rendered as a <div> element, you will see something like this:

<div id="Panel1" data-report-param="42">

Finally you would be able to grab it from Javascript using one of the following two ways:

$("#Panel1").data("report-param");

$("#Panel1").attr("data-report-param");

UPDATE on retrieving the attribute

If they are on the same node, try this:

$.each($("[id*='ReportViewer1']"), function(index, value) {
    if ($(value).is("[data-report-param]"))
    {
        alert($(value).attr("data-report-param"));
    }
});

This will go through each element that contains "ReportViewer1" in its ID. Then for each item it will check if that element contains the "data-report-param" attribute. If so, alert the value. Hope this finally helps :)

Fil
  • 74
  • 3
  • Thanks Fil. I posted the generated code. I see the webpartID. I was hoping to work down the object tree and get the reportviewer parameter. – tomepenn Dec 21 '13 at 05:41
  • As I see the reportviewer parameter lives on your server side, so if you need it visible on the client end, I don't see any other way but to pass it to the markup (like you outlined by using a hidden field or some other control). Some other options to pass the parameter from code behind is to add it as a CssClass or perhaps using HTML5 data-attributes to an existing control. You would then be able to drill down the DOM using Javascript and retrieve the parameter. – Fil Dec 22 '13 at 11:41
  • Thanks Fil. I will look into this. Can you elaborate on what you mean with "HTML5 data-attributes to an existing control"? – tomepenn Dec 23 '13 at 01:55
  • Just a cleaner way to store arbitrary data in the html (for more convenient access to Javascript). Here is a good article that explains it [link](http://html5doctor.com/html5-custom-data-attributes/). – Fil Dec 23 '13 at 23:44
  • Fil. This is excellent. I added this in the code behind and it is producing the value in the DOM. I read the article, I learned some valuable technique. Thanks a ton. – tomepenn Dec 24 '13 at 08:47
  • My only trouble not is that I have more that one instance of my report control on each tab. So each reportviewer is showing up in the DOM with their respective ClientIDs. I am struggling to get at the values using something like var reportparamattribute = document.getElementById('<%= reportviewer1.ClientID %>').data("Report-Param"); – tomepenn Dec 24 '13 at 08:49
  • Here is what is being produced in the DOM. I am not sure what I am missing here. ('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:49
  • Thanks again for your help. This is exactly what I need to get the current values so I can branch depending on this value. I just have to get the value out now :) – tomepenn Dec 24 '13 at 08:51
  • I also tried this based on the article but still can't crack this. var reportparamattribute = document.getElementById('<%= ReportViewer1.ClientID %>'); var reportparametervalue = reportparamattribute.getAttribute('data-report-param'); alert("reportparametervalue =" + reportparametervalue); – tomepenn Dec 24 '13 at 09:01
  • @tomepenn Can you edit your question, and include the HTML output of the element where the ID is and where your data-report-param is? Thanks! – Fil Dec 24 '13 at 17:20
  • Fil. That is the issue. The HTML output has it buried inside the webpart.
    – tomepenn Dec 24 '13 at 17:44
  • It doesn't matter how deep it is buried inside the webpart, if it renders in the HTML, you will be able to grab it. It would really help to see the html element with the report viewer id and data-report-param attribute. If they are on the same HTML node/element, try the code from my latest update on the answer. – Fil Dec 25 '13 at 10:43
  • Sorry. I appreciate your help. I wasn't trying to avoid posting the source, it is just that the report viewer isn't rendered, only the webparts. I posted the full page source here on dropbox. You can see 3 instances of the webpart. There is a report veiwer fully rendered on each. I also attached a screenshot. https://dl.dropboxusercontent.com/u/9305638/page%20source.txt https://dl.dropboxusercontent.com/u/9305638/screenshot%20of%20webpart.png – tomepenn Dec 25 '13 at 14:57
  • I also put the full output of the DOM. You can see the data-report-param with a value of 1068. https://dl.dropboxusercontent.com/u/9305638/DOM.txt – tomepenn Dec 25 '13 at 15:00
  • Thanks @tomepenn, could it be that it is loaded later (through AJAX), so it is not immediately visible on the initial load (and through View Source option on the browser). Do you have [Firebug](https://getfirebug.com/) for Firefox, or Google Chrome (Developer tools - hit F12)? Both Firebug and Chrome's Developer Tools, have a "Console" section, where you could run that last script I posted, when you have the Reportviewer visible on the page. This script needs to run when the report viewer has been loaded. – Fil Dec 25 '13 at 16:54
  • Fil. I ran your script and it popped the alert with the 1068 value! So it is there, I am just not doing something right in my code. The page is fully loaded to answer your question. It is just sitting there waiting for the user to click a tab or a dropdown and then it fires the javascript function to get the data-report-param and compare it to a value from a dropdown on the page (outside of the webpart). I am just not doing something right in my javascript. I will play around and let you know, but at least I know the value is there. Thanks again – tomepenn Dec 25 '13 at 21:57
  • The requirement is to get the value of data-report-param in the reportviewer control on the current tab and compare it to the value from a dropdown on another part of the page. Since the javascript is part of the webpart, I should be able to get the clientID guid for each reportviewer somehow to get the right data field value. – tomepenn Dec 25 '13 at 22:00
  • So it must be a life-cycle issue. My suspicion is that your JS is loaded before the reportviewer is being loaded (and visible). I am assuming that once a tab is being clicked, that the reportviewer is being loaded through AJAX (I am just guessing I could be wrong). If this is correct, then you have to register your script when reportviewer has been loaded. Is there a way to do it (run the script) on tab click? – Fil Dec 25 '13 at 23:58
  • Fil. In this workflow, the reportviewer is already loaded and displaying. I am waiting on the tab click to check the current data-report-param value of the already loaded reportviewer. The DOM state you saw in the link is the current state waiting on the javascript to check for the value of the data-report-param of the fully loaded reportviewer already on the page. – tomepenn Dec 26 '13 at 04:15
  • I see, so I was wrong :) Let me know if you need help with anything else, and would also like to hear from you if you were able to get this resolved. Good luck! – Fil Dec 26 '13 at 11:22
  • Thanks again for all of your help. This was a live project with tight deadlines! I posted the working code above. – tomepenn Dec 27 '13 at 09:30