title: How to make Crystal Report Viewer display report after postback
body: <p>I've got a dropdown, a label, and a CR Viewer on my page.  When I select a report from the DD, I update the label to show the currently selected report and I update the CRV to show the report.</p>
  
  <p>The label updates fine and I just put it there as a test to make sure other controls were updating properly.  The CRV, on the other hand, is always one request behind.  I pick a report and it doesn't show up.  I pick another report and then the one I previously picked shows up.</p>
  
  <p>The code posted below was from before I added the label, but nothing else is changed.</p>
  
  <pre><code>using System;
  using DataAccess;
  using CrystalDecisions.CrystalReports.Engine;
  
  namespace Reporting
  {
      public partial class CRViewer : System.Web.UI.Page
      {
          protected void Page_Load(object sender, EventArgs e)
          {
              if (IsPostBack) return;
              ReportDropDown.Items.Add("Select a report");
  
              var reports = Data.ExecutSql("select * from ngmasterdb..reports");
              while (reports.Read()) ReportDropDown.Items.Add(reports["Name"].ToString());
              reports.Close();
          }
  
          protected void ReportDropDown_SelectedIndexChanged(object sender, EventArgs e)
          {
              var reportInfo = Data.ExecutSql("select * from ngmasterdb..reports where Name = '" + ReportDropDown.SelectedValue.Replace("'", "''") + "'");
  
              try
              {
                  ReportDocument rptdoc = new ReportDocument();
  
                  if (!reportInfo.Read()) return;
                  var file = reportInfo["ReportFile"].ToString();
                  if (file == null || file.Trim() == "") return;
  
                  ReportSource.Report.FileName = file;
                  CrystalReportViewer1.RefreshReport();
              }
              finally
              {
                  reportInfo.Close();
              }
          }
      }
  }
  </code></pre>
  
  <p>I believe the only thing of interest in the aspx is that AutoPostBack is set to true for the DropDown control.  If you'd still like to see the aspx though let me know and I'll post it.</p>