JavaScript runtime error: Unable to get property 'add_init' of undefined or null reference displaying Microsoft Report Viewer ASPX control

0

BACKGROUND

I have been asked to upgrade a 10-years-old ASP.Net 2.0 web application project to the latest .Net framework and Visual Studio solution. The project must display a series of SQL Server Reporting services reports via the ReportViewer web control.

So, I have upgraded the project to use .Net Framework 4.6.1 and I am developing with Visual Studio 2017. I also upgraded the ReportViewer control to the latest available version.

THE PROBLEM

Everything seems working OK, except for the report viewer page: this is the only page that crashes with this javascript error:

0x800a138f - JavaScript runtime error: Unable to get property 'add_init'
of undefined or null reference

and this is the offending code, that is generated by the ReportViewer control itself

<script type="text/javascript">
//<![CDATA[
Sys.Application.add_init(function() {

if ((document.compatMode && document.compatMode == 'BackCompat') ||
    (document.compatMode && document.compatMode == 'CSS1Compat' && document.documentMode && (document.documentMode <= 8 && document.documentMode > 0))) {
    Sys.UI.DomElement.setVisible($get('ctl00_ContentPlaceHolder1_ReportViewer1_BrowserNotSupportedErrorMessage'), true);
    Sys.UI.DomElement.setVisible($get('ctl00_ContentPlaceHolder1_ReportViewer1_fixedTable'), false);    
} else if (typeof Microsoft == 'undefined' ||
            typeof Microsoft.Reporting == 'undefined' ||
            typeof Microsoft.Reporting.WebFormsClient == 'undefined' ||
            typeof Microsoft.Reporting.WebFormsClient.ReportViewer == 'undefined') {
    Sys.UI.DomElement.setVisible($get('ctl00_ContentPlaceHolder1_ReportViewer1_HttpHandlerMissingErrorMessage'), true);
    Sys.UI.DomElement.setVisible($get('ctl00_ContentPlaceHolder1_ReportViewer1_fixedTable'), false);
}
    $create(Microsoft.Reporting.WebFormsClient.ReportViewer, {"_internalViewerId":"ctl00_ContentPlaceHolder1_ReportViewer1_ctl03","id":"ctl00_ContentPlaceHolder1_ReportViewer1"}, null, null);
});
[omissis]

The problem is that Sys.Application does not contain an add_init method.

The page containing the ReportViewer control is quite simple:

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt" Width="100%" Height="95%" ProcessingMode="Remote" ShowCredentialPrompts="False" SizeToReportContent="True" style="overflow: auto;" >
    </rsweb:ReportViewer>
</asp:Content>

That's all; the mandatory ScriptManager required by the ReportViewer control is laid on the site master page.

WHAT I TRIED SO FAR

I spent an entire day googling this error, finding several questions, but none related to my problem: in all thast cases it turned out it was a mistake in user code; in my case, this is code generated automatically by the web control. In most cases it were either the Sys or the Application object NUL; in my case Sys.Application is not null: it simply does not contain an $add_init method (or any other method, for that).

Anyway, I tried to follow some suggestions I found in other questions, to no avail.

I also tried creating a new simple test application, that only display a report on a page: it works perfectly.

I compared the test appllication web.config with the one from my app: there were differences, that I removed; again, no luck.

I also tried to use the web.config from the test application, adding only the items strictly needed to start the program, and going directly to the report page: the error is still here.

Anyone can help me getting this report page working? If more infos/data/code snippets are needed, just ask.

Thanks in advance,

Gianfranco

c#
asp.net
reporting-services
asked on Stack Overflow Sep 19, 2018 by iw1dov

1 Answer

0

After a lot more investigations, I found that ComponentArt web controls are conflicting with .Net built-in AJAX infrastructure.

Since ComponentArt is discontinued, I would have to replace these controls with something else on every page; something I am not allowed to do for time and budget reasons.

So I ended up building a simple, totally white page conaining the ReportViewer control only, and displaying it in an Iframe placed on the original report viewer page.

Dirty, but it works. Maybe in the future there will be some budget to buy new controls and to remove those obsolete ones.

Hope this will help someone else.

answered on Stack Overflow Sep 24, 2018 by iw1dov

User contributions licensed under CC BY-SA 3.0