Click here to Skip to main content
15,030,744 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im trying to Provide print option for Report Viewer Control and but in this case it's generating following error

C#
JScript runtime error: 
Variable 'viewerReference' is going null
so Unable to get value of the property 'get_isLoading': object is null or undefined


What I have tried:

ASP.NET
<div align="center">
       <asp:Panel ID="PanelButtons" runat="server">
       <asp:Button ID="btnPrint" runat="server" Text="Print" OnClientClick="PrintReport()"/>
       </asp:Panel>
    </div>


HTML
<script language="javascript" type="text/javascript">
        function PrintReport() {
            var viewerReference = $find("ReportViewer1");
            //var viewerReference = $find('<%= ReportViewer1.ClientId %>');

            var stillonLoadState = viewerReference.get_isLoading();

            if (!stillonLoadState ) {
                var reportArea = viewerReference .get_reportAreaContentType();
                if (reportArea == Microsoft.Reporting.WebFormsClient.ReportAreaContent.ReportPage) {
                    $find("ReportViewer1").invokePrintDialog();
                }
            }
        }
       </script>
Posted
Updated 7-Aug-16 22:31pm
v3

error message here:
JavaScript
var stillonLoadState = viewerReference.get_isLoading();

because problem here:
JavaScript
var viewerReference = $find("ReportViewer1");

because $find("ReportViewer1") failed.
Are you sure ReportViewer1 exist ?
   
The error message is pretty explicit:
Unable to get value of the property 'get_isLoading': object is null or undefined

Which means that from this:
JavaScript
var stillonLoadState = viewerReference.get_isLoading();

viewerReference is null.
It's loaded here:
JavaScript
var viewerReference = $find("ReportViewer1");

So $find is returning null.
Since it returns null is it can't find a control with that ID:
Matt Berseth: The Ever-Useful $get and $find ASP.NET AJAX Shortcut Functions[^]
You need to look at your page and see what your report control is called...
   
Comments
JanardhanSharma 9-Aug-16 2:00am
   
Here is my code, I wasn't able to find why the $find("ReportViewer1") going null though if the control id is same "ReportViewer1". When if im using $get it's working fine. But that doesnt contain get_isLoading property.
i've tried the code from the following link
https://blogs.msdn.microsoft.com/selvar/2011/04/09/invoking-the-print-dialog-for-report-viewer-2010-control-using-the-javascript-api/

<pre lang="HTML">
<form id="form" runat="server" style="width: 100%; height: 100%;">
<asp:ScriptManager ID="ScriptManager1" runat="server">

<asp:Button ID="btnBack" class="classname" runat="server" Text="Back" OnClick="btnBack_Click" />
<asp:Button ID="btnClose" PostBackUrl="ReportsNewMain.aspx" class="classname" runat="server"
Text="Close" />
<rsweb:ReportViewer ID="ReportViewer1" runat="server" InteractivityPostBackMode="alwayssynchronous"
ProcessingMode="Remote" PromptAreaCollapsed="True" Width="100%" Height="515px"
DocumentMapWidth="100%" Font-Names="Verdana" Font-Size="8pt">
<serverreport reportserverurl="">

<div align="center">
<asp:Panel ID="PanelButtons" runat="server" Width="527px" BorderColor="#999999">
<asp:Button ID="btnPrint" runat="server" Text="Print"
OnClientClick="PrintReport()" />

</div>
</form>
<script language="javascript" type="text/javascript">
function PrintReport() {
try {
//var viewerReference = $find("<%= ReportViewer1.ClientID %>");
var viewerReference = $find("ReportViewer1");
//var viewerReference = $get("ReportViewer1");
var stillonLoadState = viewerReference.get_isLoading();

if (!stillonLoadState) {

var reportArea = viewerReference.get_reportAreaContentType();
if (reportArea == Microsoft.Reporting.WebFormsClient.ReportAreaContent.ReportPage) {
$find("ReportViewer1").invokePrintDialog();
}
}
}
catch (err) {
document.getElementById("demo").innerHTML = err.message;
}
}
</script>
</pre>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900