ReportViewerForMvc event when loading a report

I am loading a report in an iframe using ReportViewerForMvc. I currently have a counter, so the user will know that the report is loading. However, the counter stops rotating when the iframe is placed on the page ... not when the contents of the report end up rendering. I found people using isLoading with $ find, but I'm sure this is easy for asp, and I need me to be in .Net

What is the easiest way to get spinner to keep spinning until report is loaded in iframe?

I currently have a general view for all reports that I hope to add javascript for:

@using ReportViewerForMvc;

<div id="reportViewer">@Html.ReportViewer(Model.ReportViewer as Microsoft.Reporting.WebForms.ReportViewer)</div>
+4
source share
1 answer

iframe onload does not work to stop spinner here. To do this, you will need cookies and the client side of the script. The server code sets the value in the cookie. When the report is displayed, the value will be read on the client side (cshtml), and the counter can be stopped.

Read this article. Here you can replace the blocker with a counter.

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>
0
source

Source: https://habr.com/ru/post/1678285/


All Articles