Building dynamic reportviewer, using AJAX call and reportviewer.rendercontrol(htmltextwriter) RRS feed

  • Question

  • i have careated a report "MyReport.rdlc" and a dataser "DataSet1" with one table "Employee"

    following is the code that i have tried to build a report and write the html in response. The line with "rptViewer.RenderControl(oHtmlWrt)" runs fine but html it generates says "ASP.NET ViewState has been disabled. The Report Viewer control requires that ViewState be enabled." so can anyone please help me what i am doig wrong??

            HtmlTableRow rowMain = new HtmlTableRow();
            DataSet1 oDS = new DataSet1();
            DataSet1.EmployeeRow oRow = oDS.Employee.NewEmployeeRow();
            oRow.EmployeeID = 112;
            oRow.EmpFName = "meme";
            HtmlForm form = new HtmlForm();
            HtmlTable tblMain = new HtmlTable();
                if (File.Exists(Server.MapPath("~\\MyReport.rdlc")))
                    HtmlTableCell tblCell = new HtmlTableCell();
                    ReportViewer rptViewer = new ReportViewer(); //creating report viewer for each entity                                       
                    form.Attributes.Add("runat", "server");
                    tblMain.CellPadding = 3;
                    tblMain.CellSpacing = 3;
                    rptViewer.EnableViewState = true;
                    rptViewer.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Local;
                    rptViewer.LocalReport.EnableHyperlinks = true;
                    rptViewer.LocalReport.ReportPath = Server.MapPath("~\\MyReport.drlc");
                    rptViewer.LocalReport.ReportEmbeddedResource = (Convert.ToString("MyReport") + ".rdlc");
                    if (oDS != null) //alots the datasource for dashboard
                        rptViewer.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", oDS.Tables[0]));
                    rptViewer.EnableViewState = true;
                    rptViewer.Visible = true;
                    StringWriter oStrWrt = new StringWriter();
                    HtmlTextWriter oHtmlWrt = new HtmlTextWriter(oStrWrt);

    Monday, August 24, 2009 8:21 AM

All replies

  • It's not clear when this code is executing in the ASP.Net page execution cycle, but the report viewer requires that is run through the normal sequence of events (OnLoad, OnPreRender, etc).  You are receiving this exception because the SaveViewState event never occured.  The viewer (and most ASP.Net controls) simply aren't designed to be invoked this way, outside of the normal ASP.Net workflow.

    Additionally, the current report viewer will not work with ASP.Net AJAX.  We are working on support for this and it will be available beginning in VS 2010 beta 2.

    Monday, August 31, 2009 5:04 AM