报告加载时的ReportViewerForMvc事件

时间:2017-05-31 18:20:45

标签: iframe reporting-services webforms reportviewer client-side

我正在使用ReportViewerForMvc在iframe中加载报表。目前,我有一个微调器,以便用户知道报告正在加载。但是,当iframe放在页面上时,微调器停止旋转...而不是在报表内容完成渲染时。我发现人们使用带有$ find的isLoading,但我很确定这只是针对asp而我需要我才能进入.Net

在iframe中加载报表之前,让微调器继续旋转的最简单方法是什么?

目前,我对所有报告的共享视图,我希望添加一些javascript到:

@using ReportViewerForMvc;

<div id="reportViewer">@Html.ReportViewer(Model.ReportViewer as Microsoft.Reporting.WebForms.ReportViewer)</div>

1 个答案:

答案 0 :(得分:0)

iframe onload不能在这里停止微调器。你需要cookie和客户端脚本来完成它。 服务器代码将在cookie中设置值。一旦呈现报告,将在客户端(cshtml)读取值,并且可以停止微调器。

阅读这篇文章。在这里你可以用微调器替换阻挡器。

http://gruffcode.com/2010/10/28/detecting-the-file-download-dialog-in-the-browser/

   //This should be called on the event when you are loading the report 
   //In your case you will route the url to controller or invoke the link 
   //for the report 

 $(document).ready(function () {
 $('#create_pdf_form').submit(function () {
  blockUIForDownload();
});

});

//This is where you will place the spinner
function blockUIForDownload() {
 var token = new Date().getTime(); 
  //use the current timestamp as the token value
  $('#download_token_value_id').val(token);
  $.blockUI();
  fileDownloadCheckTimer = window.setInterval(function () {
   var cookieValue = $.cookie('fileDownloadToken');
   if (cookieValue == token)
     finishDownload();
   }, 1000);
}
 //This will read the token generated from the server side controller or 
 //aspx.cs or ashx handler
 function finishDownload() {
    window.clearInterval(fileDownloadCheckTimer);
    // $.removeCookie('fileDownloadToken'); //clears this cookie value
    //$.cookie('fileDownloadToken', null);
    //$.removeCookie("fileDownloadToken");
    setCookie("fileDownloadToken", '2')
    $.unblockUI();
}


//On the server side set the token , it could be controller or ashx handler
  var response = HttpContext.Current.Response;
  response.Clear();
   response.AppendCookie(new HttpCookie("fileDownloadToken", 
 downloadTokenValue); //downloadTokenValue will have been provided in the 
 form submit via the hidden input field

  response.Flush();

  //Lastly don't forget to add these source js files.
  <script src="~/Scripts/jquery-1.5.1.js"></script>
  <script src="~/Scripts/jquery.blockUI.js"></script>
  <script src="~/Scripts/jquery.cookie.js"></script>