title: How do I release a Crystal Report object when an asp.net page closes
body: <p>I have a asp .net 3.5 app using Crystal Reports for Visual Studio 2010.</p>
  
  <p>I have an issue with a report preview screen.</p>
  
  <p>If I don't dispose of the report object in the page unload the object stays active and never goes away until the application pool of the site is recycled. Also, the temp files created by the report are not cleaned up at that point. </p>
  
  <p>If I dispose of the report object in the form unload, the object is released and the temp files are removed.</p>
  
  <p>But if I do that, then the report object is gone and if the user selects the option to export the report (from the viewer control on the page that is still open) I get the error:</p>
  
  <pre><code>not set to an instance of on object
  </code></pre>
  
  <p>In my ReportViewer page I just have the viewer control.</p>
  
  <p>In the page load I create the report object and pass it to the viewer. This all works great.</p>
  
  <p>My disposal code is the a method that handles <code>MyBase.Unload</code>, right now my problem is that this event is fired even when the page isn't being closed and I cant find an event that would be like the closing event on a normal window.</p>
  
  <p><strong>What do i need to do to properly dispose of the report object, but not until after the viewer is actually closed?</strong></p>