title: Multiple Reports with ReportViewer and SSRS 2008 in Silverlight
body: <p>There is a lot of information out there about using the ReportViewer control in Silverlight to display multiple reports but I can't get any of them to work for me in my situation because the way I have everything set up is a little different.  We had to be able to send post data to the page the ReportViewer is on so a little bit of javascript had to be added in to actually open the page.  </p>
  
  <p>Most of the info online talks about just adding the line ReportViewerCtrl.reset() and it should work but for me it makes absolutely no difference.  I'm fairly confident the code will explain the situation better but if you need more details about the set up, please, just ask.  </p>
  
  <p>So... from the beginning... the hyperlink button for the report calls this on click:  <code>HtmlPage.Window.Invoke("showAspPage", par);</code></p>
  
  <p>That calls this script (I have cut out everything that handles the report parameters and stuff because it works just the same when that data is excluded anyway):</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  var g_htmlWindow;
  
  function showAspPage(param) {
      var to = param["to"];
      var myForm = document.createElement("form");
      myForm.method = "post";
      myForm.action = to;
      myForm.setAttribute("target", "_blank");  
  
      //handle parameters here
  
      document.body.appendChild(myForm);
      myForm.submit();
      document.body.removeChild(myForm);
   }
  &lt;/script&gt;
  </code></pre>
  
  <p><code>param["to"]</code> is the link to the page the actual <code>ReportViewer</code> control is on... so from the aspx portion of that page:</p>
  
  <pre><code>&lt;body&gt;
  &lt;form id="form1" runat="server"&gt;
          &lt;asp:ScriptManager ID="ScriptManager1" runat="server"&gt; &lt;/asp:ScriptManager&gt;
          &lt;rsweb:ReportViewer ID="ReportViewer4" runat="server"&gt; &lt;/rsweb:ReportViewer&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>And the important chunk from the aspx.cs portion of the <code>ReportViewer</code> page... (might be over-kill on setting properties and such but I've added a lot of stuff while trying out what suggestions I found on the web)</p>
  
  <pre><code>ReportViewer4.Reset();  
  ReportViewer4.ShowCredentialPrompts = false;
  ReportViewer4.ServerReport.ReportServerCredentials = new ReportCredentials();
  ReportViewer4.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
  ReportViewer4.ServerReport.ReportServerUrl = reportServerURL
  ReportViewer4.AsyncRendering = false;
  
  ReportViewer4.ServerReport.ReportPath = reportPath;
  ReportViewer4.KeepSessionAlive = true; 
  
  ReportViewer4.ServerReport.SetParameters(params);
  
  ReportViewer4.SizeToReportContent = true; 
  ReportViewer4.Width = Unit.Pixel(900);
  ReportViewer4.ServerReport.Refresh();
  </code></pre>
  
  <p>When I only want to see one report, everything works fine - everything is set up correctly.  But, when I want to call <code>HtmlPage.Window.Invoke("showAspPage", par);</code> twice in a row for two different reports I start getting this error either when one of the reports loads or when you try and change the report parameters in either of the two reports:  <strong>ASP.NET session has expired or could not be found</strong> Both reports load 95% of the time - with parameters, data, everything; one report always loads but it depends on which one finishes loading first; but you can't change the parameters without that error.</p>
  
  <p>So.... as a slight alternative, in this situation, the ability to change the report isn't actually needed and I could do a direct export to PDF but with scripting involved you can't simply add "rs:Format=PDF" to the end of the report path.  However, if the parameters are visible, they need to work if changed.  I guess I could hide the whole parameter section?  But it still doesn't solve the issue of getting the error when the report loads sometimes....</p>
  
  <p>Also.... might be entirely unrelated, but the parameters are encrypted and I have to get the salt and hash from the database (Entity Framework and WCF RIA Services) before I call HtmlPage.Window.Invoke.... I find this kind of weird.... but, after the report screen loads, if the user sits there and doesn't click on anything (but doesn't sit there long enough to actually be logged out, maybe just 5 min or so), I get this error:
  <strong>'Load operation failed for query 'GetStuff'. The remote server returned an error: Not Found.'</strong> but again, it works fine if clicked right away.  I've never had that happen until I started this two reports at once thing, though. </p>
  
  <p>Please... any advice.... or suggestions... or alternatives... or links... </p>
  
  <p>Thanks.</p>
  
  <hr>
  
  <p>So... I tried to just hide the whole parameters section but the user still needs to be able to print and export.  It works fine for one of the reports but on the other one I get this on the whole window (when exporting to PDF for both reports): </p>
  
  <pre><code>[AspNetSessionExpiredException: ASP.NET session has expired or could not be found]
  Microsoft.Reporting.WebForms.ViewerDataOperation..ctor() +330
  Microsoft.Reporting.WebForms.ReportDataOperation..ctor(Boolean requiresFullReportLoad) +120
  Microsoft.Reporting.WebForms.ReportDataOperation..ctor() +33
  Microsoft.Reporting.WebForms.ExportOperation..ctor() +29
  Microsoft.Reporting.WebForms.HttpHandler.GetHandler(String operationType) +188
  Microsoft.Reporting.WebForms.HttpHandler.ProcessRequest(HttpContext context) +111
  System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +100
  System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +75
  </code></pre>