title: How to generate a print preview in a single button click in report viewer?
body: <p>This is my aspx page..................</p>
  
  <pre><code>    &lt;asp:Panel ID="UpdatePanel1" runat="server" Visible="false" &gt;   
             &lt;rsweb:ReportViewer ID="ReportingForPrintingReportViewer" runat="server"
             Width="100%" Height="100%" Font-Names="Verdana" Font-Size="8pt"
             InteractiveDeviceInfos="(Collection)" WaitMessageFont-Names="Verdana"
             WaitMessageFont-Size="14pt"&gt;  
             &lt;LocalReport ReportPath="Report.rdlc"&gt;
             &lt;DataSources&gt;
             &lt;rsweb:ReportDataSource DataSourceId="ObjectDataSource2" Name="DataSet1" /&gt;
             &lt;/DataSources&gt;
             &lt;/LocalReport&gt;
             &lt;/rsweb:ReportViewer&gt;  
             &lt;asp:ObjectDataSource ID="ObjectDataSource2" runat="server" 
               SelectMethod="GetData" TypeName="DataSet1TableAdapters.tblTotalFeeTableAdapter"&gt;
             &lt;/asp:ObjectDataSource&gt;
                   &lt;/asp:Panel&gt;
  &lt;asp:Button ID="btnSubmit" runat="server" Text="Submit" Width="150px"
             onclick="btnSubmit_Click" /&gt;
         &lt;asp:Button ID="btnReset" runat="server" Text="Reset" Width="150px" /&gt;
         &lt;asp:Button ID="btnCreateBill" runat="server" Text="CreateBill" Width="150px" 
             onclick="btnCreateBill_Click"/&gt;
  
  
         &lt;asp:PopupControlExtender ID="btnCreateBill_PopupControlExtender" OffsetX="-1100" OffsetY="115" 
             runat="server" DynamicServicePath="" Enabled="True" ExtenderControlID="" 
             TargetControlID="btnCreateBill" PopupControlID="UpdatePanel1"&gt;
         &lt;/asp:PopupControlExtender&gt;
  </code></pre>
  
  <p>This is my cs page</p>
  
  <pre><code> protected void btnCreateBill_Click(object sender, EventArgs e)
      {
          DisplayReport();
          UpdatePanel1.Visible = true;
  
      }
      private DataTable TotalInfoData()
      {
          try
          {
              //DataClassesDataContext db = null;
              //db = new DataClassesDataContext();
              //var s = from p in db.tblTotalFeess
              //        where p.Class == ClassDropDownList.SelectedItem.Value &amp;&amp; p.StudentID == Convert.ToInt32(StudentNameDropDownList.SelectedValue)
              //        select p;
  
              //DataTable dt = new DataTable();
              //SQLHelper sqhlpr = new SQLHelper();
              //sqhlpr.SqlText = "select * from tblTotalFee where Class='" + ClassDropDownList.SelectedItem.Value + "'" + "and StudentID='" + StudentNameDropDownList.SelectedValue + "'";
              //DataTable dt = sqhlpr.getDataTable(false);
              //return dt;
              try
              {
                  // Open Sql Connection  
                  SqlConnection SqlCon = new SqlConnection(@"Data Source=PRATIKPC;Initial Catalog=dbbilling2.0;Integrated Security=True");
                  SqlCon.Open();
  
                  // Create a Command  
                  SqlCommand SqlComm = new SqlCommand();
                  SqlComm.Connection = SqlCon;
                  SqlComm.CommandType = CommandType.Text;
                  SqlComm.CommandText = "select * from tblTotalFee where Class='" + ClassDropDownList.SelectedItem.Value + "'" + "and StudentID='" + StudentNameDropDownList.SelectedValue + "'";
  
                  // Create instance of Northwind DataSetXSD  
                  DataSet1.tblTotalFeeDataTable dtbl = new DataSet1.tblTotalFeeDataTable();
  
                  // Set a Data Commands  
                  SqlDataAdapter SqlDa = new SqlDataAdapter(SqlComm);
                  SqlDa.Fill(dtbl); // Fill Data in NorthwindDataSet Object.  
  
                  return dtbl;
  
              }
              catch (Exception ex)
              {
                  throw new Exception(ex.Message);
              }  
  
          } 
  
          catch (Exception ex)
          {
              throw new Exception(ex.Message);
          }
      }
      private void DisplayReport()
      {
          try
          {
              // Clear the Data Source   
              ReportingForPrintingReportViewer.LocalReport.DataSources.Clear();
  
              // Set a DataSource to the report  
  
              // First Parameter - Report DataSet Name  
              // Second Parameter - DataSource Object i.e DataTable  
              ReportingForPrintingReportViewer.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", TotalInfoData()));
  
              // OR Set Report Path  
              ReportingForPrintingReportViewer.LocalReport.ReportPath = HttpContext.Current.Server.MapPath("~/Report.rdlc");
  
              // Refresh and Display Report  
              ReportingForPrintingReportViewer.LocalReport.Refresh();
  
          }
          catch (Exception ex)
          {
              throw new Exception(ex.Message);
          }
      }
  </code></pre>
  
  <p>I have to click btnCreateBill twice to generate report viewer. Why? And how can I generate report viewer in a single click of a button?</p>