Link to home
Start Free TrialLog in
Avatar of enterpriseireland
enterpriseireland

asked on

writing crystal report to reponse using ExportToHttpResponse only works with server.transfer

Hi all,
Im trying to show a crystal report in pdf format in the browser but something very odd is going on and i cant work out why.

I have a page which lists reports (Reports.aspx)
I found the code below to generate a report in PDF format.
This code works fine when i have the code in a button click event in Reports.aspx.

People want the report in a different page so they can view a report,go back,choose another, go back etc..
So I created a new page (GenerateReport.aspx) put the code in page_load and did a reponse.redirect to GenerateReport.aspx in the button click event instead.
For some reason this doesnt work anymore! It just shows a blank screen.

I tried the code in page_load of the Reports.aspx page and it wont work either.
Even odder, if i change the Response.Redirect to Server.Transfer() it works!

I thought I could get away with Server.Transfer but users are closing the report window or clicking back and getting taken to the wrong page because Server.Transfer doesnt do a new request. Ive no idea why it works one way and not the other!
Has any one any ideas at all?
Thanks!!

IList<ReportData> myData = GetReportData();
CrystalReport1 myCrystalReport = new CrystalReport1();
myCrystalReport.SetDataSource(myData);

Response.Buffer = false;
Response.ClearContent();
Response.ClearHeaders();
myCrystalReport.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, false, "ExportedReport");

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of JayFromPep
JayFromPep
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of enterpriseireland
enterpriseireland

ASKER

I gave up on this.  I just had to do a fudge in the end. thanks for the help.
wasnt full answer but was a good try :)