/// <summary> /// Define the report to use in Page_Init. The ReportViewer uses view state to persist its data, you should use Page_Init instead of Page_Load to specify /// ReportViewer properties that are constant for the life of the page. Since Page_Load occurs after the view state is loaded, setting the report parameters, /// for example, in Page_Load can cause the ReportViewer control to treat the specified data as newer than the one in the view state and re-process the report. /// You can also avoid this in Page_Load by specifying ReportViewer data in an if(!IsPostBack){} block. /// </summary> protected void Page_Init(object sender, EventArgs e) { ReportViewer1.ProcessingMode = ProcessingMode.Remote; // Get report path from configuration file ReportViewer1.ServerReport.ReportServerUrl = new Uri(ConfigurationManager.AppSettings["ReportServerUrl"]); ReportViewer1.ServerReport.ReportPath = String.Format("{0}/{1}{2}", ConfigurationManager.AppSettings["SampleReportsPath"], // folder or site path "Employee Sales Summary 2008", // report name (ConfigurationManager.AppSettings["ReportServerMode"] == "SharePoint" ? ".rdl" : String.Empty)); // extension, depending on the report server mode // (for information on the report path format, // see http://msdn.microsoft.com/en-us/library/ms252075.aspx) // Set export options for the report. In this example, since a static report is displayed, so the export options are always the same. The options should // be repopulated if the report is dynamically changed in your page. RenderingExtension[] extensions = ReportViewer1.ServerReport.ListRenderingExtensions(); foreach (RenderingExtension extension in extensions) { // Remove the non-visible rendering formats from the drop-down list. if (extension.Visible) { DropDownListExport.Items.Add(new ListItem(extension.LocalizedName, extension.Name)); } } // Use the RegisterPostBackControl() method to register the custom toolbar items with the ReportViewer control, // so that actions on these items can cause the wait control to be displayed. ReportViewer1.RegisterPostBackControl(ButtonFirstPage); ReportViewer1.RegisterPostBackControl(ButtonPreviousPage); ReportViewer1.RegisterPostBackControl(TextBoxPageNumber); ReportViewer1.RegisterPostBackControl(ButtonNextPage); ReportViewer1.RegisterPostBackControl(ButtonLastPage); ReportViewer1.RegisterPostBackControl(ButtonBackToParent); ReportViewer1.RegisterPostBackControl(TextBoxFindString); ReportViewer1.RegisterPostBackControl(ButtonFind); ReportViewer1.RegisterPostBackControl(ButtonNext); ReportViewer1.RegisterPostBackControl(ButtonRefresh); }