2007
Render Local Report on Button Click
I needed to render a local report to pdf on a button click. This was not the first time i’ve done it without any problems but this time, the following problem was loaded…
Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules or server trace is enabled.
Details:Â Error parsing near ‘%PDF-1.3%
1 0 obj’.
Next is the coding i normally use to render the report…
private void RenderReport()
{
LocalReport localReport = new LocalReport();
localReport.ReportPath = Server.MapPath(“Reports/Daily.rdlc”);
source_Daily.DataBind();
//Give the collection a name (EmployeeCollection) so that we can reference it in our report designer
ReportDataSource reportDataSource = new ReportDataSource(“Analyze_ReportDaily”, source_Daily);
localReport.DataSources.Add(reportDataSource); string reportType = “PDF”;string mimeType;string encoding;
string fileNameExtension;
//The DeviceInfo settings should be changed based on the reportType
//http://msdn2.microsoft.com/en-us/library/ms155397.aspx
string deviceInfo = “<DeviceInfo>” +” <OutputFormat>PDF</OutputFormat>” +” <PageWidth>8.5in</PageWidth>” +” <PageHeight>11in</PageHeight>” +” <MarginTop>0.3in</MarginTop>” +” <MarginLeft>0.0in</MarginLeft>” +” <MarginRight>0.0in</MarginRight>” +” <MarginBottom>0.3in</MarginBottom>” +“</DeviceInfo>”; Warning[] warnings; string[] streams;byte[] renderedBytes;//Render the report
renderedBytes = localReport.Render(reportType, deviceInfo, out mimeType, out encoding,out fileNameExtension, out streams, out warnings);//Clear the response stream and write the bytes to the outputstream//Set content-disposition to “attachment” so that user is prompted to take an action
//on the file (open or save) Response.Clear();Response.ContentType = mimeType; Response.AddHeader(“content-disposition”, “attachment; filename=foo.” + fileNameExtension);
Response.BinaryWrite(renderedBytes);
Response.End();Â
}
 To solve the previous error, cut the following code:
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader(“content-disposition”, “attachment; filename=foo.” + fileNameExtension);
Response.BinaryWrite(renderedBytes);
Response.End();
And insert the next code:Â
Session["report"] = renderedBytes;
System.Text.StringBuilder _sb = new System.Text.StringBuilder();
_sb.Append( “window.open(‘../Report.aspx’,”,”);
_sb.Append(“‘toolbar=0,menubar=0,resizable=yes’)”);
ScriptManager.RegisterStartupScript(Page, Page.GetType(), “winOpen”, _sb.ToString(), true);
 Also create a new web page, name it Report.aspx and insert the following code in the Page_Load:
string extension = “PDF”;
Response.ContentType = “application/pdf”;
// set the MIME type here
Response.AddHeader(“content-disposition”, “attachment; filename=Test.” + extension);
Response.BinaryWrite((byte[])Session["report"]);
This should solve the problem. It’s a bit long but that’s the only solution i found that works fine. If you find a simpler way, please let me know to render a report on button click, please let me know. I would be happy to update the coding.
Happy Reporting!!
Reference: http://forums.asp.net/p/1183238/2013836.aspx
10 Comments
Leave a comment
What you missed
Check these Out!
Favourite Links
Tags
Archives
- May 2013 (1)
- January 2013 (2)
- December 2012 (5)
- November 2012 (4)
- October 2012 (3)
- September 2012 (1)
- August 2012 (4)
- July 2012 (2)
- June 2012 (1)
- May 2012 (10)
- February 2012 (6)
- December 2011 (2)
- October 2011 (3)
- September 2011 (1)
- April 2011 (6)
- March 2011 (14)
- February 2011 (9)
- January 2011 (10)
- December 2010 (6)
- November 2010 (10)
- October 2010 (6)
- September 2010 (10)
- August 2010 (4)
- June 2010 (10)
- May 2010 (2)
- April 2010 (1)
- March 2010 (1)
- July 2009 (1)
- June 2009 (1)
- April 2009 (4)
- March 2009 (1)
- February 2009 (5)
- January 2009 (10)
- December 2008 (8)
- November 2008 (4)
- September 2008 (6)
- August 2008 (11)
- June 2008 (2)
- May 2008 (3)
- March 2008 (1)
- February 2008 (1)
- November 2007 (1)
- September 2007 (2)
- July 2007 (2)
- June 2007 (1)
- May 2007 (2)
- February 2007 (3)
- January 2007 (4)
- November 2006 (1)
- October 2006 (1)
Categories
- Android (3)
- Apple (5)
- ASP.Net (37)
- Be Creative (1)
- Blackberry OS (1)
- CMS (5)
- Creative Computing (4)
- Crystal Reports (5)
- Day to Day (21)
- Deep Design Malta (8)
- Design and Development (22)
- Development Tools (15)
- Facebook (1)
- Games (3)
- Google Analytics (3)
- Google Gmail (1)
- Hotmail (1)
- Internet Explorer (7)
- iPhone/3G (19)
- iPod Touch (6)
- JavaScript (13)
- JQuery (2)
- Lumia (4)
- Microsoft (18)
- Microsoft SQL Server (21)
- Microsoft Visual Studio (27)
- MS Office (3)
- MVC (2)
- My Blog (3)
- NetBeans (1)
- Nokia (4)
- Off Topic (16)
- Online Services (3)
- Permissions (1)
- Phones and Tablets Platforms (7)
- Project NINE (11)
- PSP NGP (1)
- Quickie (9)
- SEO (7)
- Silverlight For WP7 (4)
- Sitefinity (1)
- Sony (1)
- Uncategorized (32)
- Utilities (57)
- VB .Net (1)
- Windows 7 (14)
- Windows 8 (3)
- Windows Live (3)
- Windows Mobile (5)
- Windows Phone 7 (18)
- Windows Phone 8 (1)
- Windows Vista (15)
- Wordpress (1)
- WP Apps (2)
- Yellow Pages (4)




Wish i had the talent to write such posts.
I came across the same problem, but I noticed that the button that i was trying to run the script from was within an update panel, which throws this error, outside it, it works perfectly.
After searching long and hard, I found two solutions:
1) move the button to be outside of the update panel
2) add a “POSTBACK TRIGGER” (not AsyncPostback Trigger) … and add the button
Hope that helps
)
hey thanks a lot…myself and team were debugging this issue from yest..but we came across ur answer through javascript error…
thanks a ton
Thanks for posting your solutions… it helps me so much
Thanks very much for your comments. I really appreciate!
Thank you very much !
I was blocked for a couple of days, and now it works !!
HI,
You can try this also.. Remove the “ID” of the control
Salam! I ve got the same problem but my button control is not within an update panel, I’m working with VS .net 2008! thanks
i getting the error an error occured during local processing
LocalReport localReport = new LocalReport();
localReport.ReportPath = @”E:Raja PalanisamyNxGsrctrunkCommunicationReportWorkSheet.rdlc”;
Microsoft.Reporting.WebForms.ReportDataSource rds = new ReportDataSource(“dtBasicPlanDetails”, dtBasicPlanDetails);
Microsoft.Reporting.WebForms.ReportDataSource rds1 = new ReportDataSource(“dtBasicCoverage”, dtBasicCoverage);
Microsoft.Reporting.WebForms.ReportDataSource rds2 = new ReportDataSource(“dtBasicPremium”, dtBasicPremium);
Microsoft.Reporting.WebForms.ReportDataSource rds3 = new ReportDataSource(“dtUnitMultiplier”, dtUnitMultiplier);
Microsoft.Reporting.WebForms.ReportDataSource rds4 = new ReportDataSource(“dtDependentPlanDetails”, dtDependentPlanDetails);
Microsoft.Reporting.WebForms.ReportDataSource rds5 = new ReportDataSource(“dtDependentCoverage”, dtDependentCoverage);
Microsoft.Reporting.WebForms.ReportDataSource rds6 = new ReportDataSource(“dtDependentPremium”, dtDependentPremium);
Microsoft.Reporting.WebForms.ReportDataSource rds7 = new ReportDataSource(“dtDependentUnitMultiplier”, dtDependentUnitMultiplier);
Microsoft.Reporting.WebForms.ReportDataSource rds8 = new ReportDataSource(“dtSuppliPlanDetails”, dtSuppliPlanDetails);
Microsoft.Reporting.WebForms.ReportDataSource rds9 = new ReportDataSource(“dtSuppliCoverage”, dtSuppliCoverage);
Microsoft.Reporting.WebForms.ReportDataSource rds10 = new ReportDataSource(“dtSuppliPremium”, dtSuppliPremium);
Microsoft.Reporting.WebForms.ReportDataSource rds11 = new ReportDataSource(“dtSuppliUnitMultiplier”, dtSuppliUnitMultiplier);
localReport.DataSources.Add(rds);
localReport.DataSources.Add(rds1);
localReport.DataSources.Add(rds2);
localReport.DataSources.Add(rds3);
localReport.DataSources.Add(rds4);
localReport.DataSources.Add(rds5);
localReport.DataSources.Add(rds6);
localReport.DataSources.Add(rds7);
localReport.DataSources.Add(rds8);
localReport.DataSources.Add(rds9);
localReport.DataSources.Add(rds10);
localReport.DataSources.Add(rds11);
//localReport.DataSources.Clear();
string reportType = “PDF”;
string mimeType;
string encoding;
string fileNameExtension;
//The DeviceInfo settings should be changed based on the reportType
string deviceInfo =
“” +
” PDF” +
” 8.5in” +
” 11in” +
” 0.5in” +
” 1in” +
” 1in” +
” 0.5in” +
“”;
Warning[] warnings;
string[] streams;
byte[] renderedBytes;
//Render the report
renderedBytes = localReport.Render(
reportType,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
//Clear the response stream and write the bytes to the outputstream
//Set content-disposition to “attachment” so that user is prompted to take an action
//on the file (open or save)
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader(“content-disposition”, “attachment; filename=foo.” + fileNameExtension);
Response.BinaryWrite(renderedBytes);
Response.End();
Oh my goodness! Impressive article dude! Thanks, However
I am going through issues with your RSS. I don’t understand the reason why I am unable to join it. Is there anyone else having similar RSS problems? Anybody who knows the solution can you kindly respond? Thanx!!