Can't find ReportViewer event for rendering complete

泪湿孤枕 提交于 2019-12-05 01:29:53

One option would be to continuously poll the isLoading property of the client side ReportViewer api. If the isLoading property returns true continue showing the progress indicator, if it returns false hide it and stop polling.

I haven't tried it myself but according to the documentation is look like it should work.

I know this is old, but I wasn't satisfied with the polling approach. You can register a property change listener for changes to isLoading instead (as described here).

In summary, add a bit of javascript to the script manager e.g. in your form element:

<asp:ScriptManager ID="scriptManager" runat="server">
    <Scripts>
        <asp:ScriptReference Path="~/Reports/ReportViewer.js" />
    </Scripts>
</asp:ScriptManager>
<rsweb:ReportViewer ID="reportViewer" runat="server"/>

Then hook it up and add any client-side logic you need in ReportViewer.js:

Sys.Application.add_load(function () {
    $find("reportViewer").add_propertyChanged(viewerPropertyChanged);
});

function viewerPropertyChanged(sender, e) {
    if (e.get_propertyName() == "isLoading") {
        if ($find("reportViewer").get_isLoading()) {
            // Do something when loading starts
        }
        else {
            // Do something when loading stops
        }
    }
};

I achieve this using JQuery like so:

$(document).ready(function () {

document.getElementById('ctl00_ctl00_DefaultContent_AdminContent_reportViewer').ClientController.CustomOnReportLoaded = function () { 
alert('You see this after Report is Generated');
}
});

Try below code snippet:

<script type="text/javascript">
    var app = Sys.Application;
    app.add_init(ApplicationInit);

    function ApplicationInit(sender) {
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        $('#ReportViewer1_ctl05').css('width', '1047px');
        if (!prm.get_isInAsyncPostBack()) {
            prm.add_endRequest(EndRequest)
        }
    }

    function EndRequest(sender, args) {
        var reportViewerControlId = "ReportViewer1";
        if (sender._postBackControlClientIDs[0].indexOf(reportViewerControlId) >= 0) {
            // do your stuff
        }
    }
</script>  

EndRequest function will be triggered once report rendering gets completed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!