Solved

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

Posted on 2010-09-03
3
1,843 Views
Last Modified: 2012-08-14
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

0
Comment
Question by:enterpriseireland
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
JayFromPep earned 250 total points
ID: 33618293
Server.Transfer works because it is passing the entire object, whereas Response.Redirect, redirects the user, leaving behind all of the stuff on the page you are leaving, unless you explicitly pass stuff forward.

so the myCrystalReport is killed on response.redirect, but lives on in Server.Transfer

Try passing the myCrystalReport into the Response.Redirect as a parameter and see if you can work with it that way.
0
 

Author Comment

by:enterpriseireland
ID: 33858290
I gave up on this.  I just had to do a fudge in the end. thanks for the help.
0
 

Author Closing Comment

by:enterpriseireland
ID: 33858296
wasnt full answer but was a good try :)
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now