ReportViewerForMvc event on report load

Viewed 1217

I am loading a report in an iframe using ReportViewerForMvc. Currently, I have a spinner so that the user will know the report is loading. However, the spinner stops spinning when the iframe is placed on the page...not when the content of the report is finished rendering. I have found people using isLoading with $find but I am pretty sure that is just for asp and I need my to be in .Net

What is the simplest way to have spinner continue to spin until the report is loaded in the iframe?

Currently, I have a shared view for all reports that I am hoping to add some javascript to:

@using ReportViewerForMvc;

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

iframe onload does not work to stop spinner here.You would need cookies and client side script to accomplish that. The server code will set the value in the cookie .Once the report is rendered the value will be read on the client side(cshtml) and spinner can be stopped.

Read this article.Here you can replace the blocker with the spinner.

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>
Related