locked
Report dissapear on postback RRS feed

  • Question

  • Hi all,

    I am using Crystal Report for VS 2005 to develop an Asp page.Below is the code is use to display my report in a button click event.

    OdbcDataAdapter myAdap = new OdbcDataAdapter();

    myAdap.SelectCommand = myCmd;

    DataSet ds = new DataSet();

    myAdap.Fill(ds);

    ds.WriteXml(@"c:\dataset_summary.xml", XmlWriteMode.WriteSchema);

    string reportPath = Server.MapPath("Crystal/projectsummary.rpt");

    myReport.Load(reportPath);

    myReport.SetDataSource(ds);

    myCrystalReportViewer.ReportSource = myReport;

    The report is displayed but when i click on the Export button or the Print button, the report dissapear. Any idea why this occurs and how to solve it?

    Wednesday, November 8, 2006 9:47 AM

Answers

  • You must refresh and bind the crystal report document object to the report viewer again in the Page_Load event when a postback occures. The export and print functionality will work if you do this.
    Friday, December 1, 2006 11:05 AM
  • The best way is once you have created your report and set the datasource to put the reportDocument object in session.  then you can pass the object in session to the viewer on every postback.

    ie.

    Create my report, set the datasource
    session.Add("report", myReport)
    crystalreportviewer1.reportsource = Ctype(session("report"), ReportDocument)

    then on every postback you need to pass the report to the viewer
    crystalreportviewer1.reportsource = Ctype(session("report"), ReportDocument)

    Friday, December 1, 2006 7:19 PM

All replies

  • You must refresh and bind the crystal report document object to the report viewer again in the Page_Load event when a postback occures. The export and print functionality will work if you do this.
    Friday, December 1, 2006 11:05 AM
  • The best way is once you have created your report and set the datasource to put the reportDocument object in session.  then you can pass the object in session to the viewer on every postback.

    ie.

    Create my report, set the datasource
    session.Add("report", myReport)
    crystalreportviewer1.reportsource = Ctype(session("report"), ReportDocument)

    then on every postback you need to pass the report to the viewer
    crystalreportviewer1.reportsource = Ctype(session("report"), ReportDocument)

    Friday, December 1, 2006 7:19 PM
  • I have tried and write the code

     

    CRBMAViewer.ReportSource = Session("report")

    CRBMAViewer.DataBind()

    int the load event but when i click the printer button and export button the report is still there and there is no asking for report printout

    if tried multiple times the report is displaying there continuously. and not printed.

    Friday, December 8, 2006 6:45 AM
  • The viewer load the reportdocument object found in the session in each load event. thats why the report is displayed continuously.

    i use a if(!Page.Postback) and Sessions.Clear() to clear the session why i am going to load the report for the 1st time

    Friday, December 8, 2006 10:29 AM
  •  

    I have tried all things but report is not displaying in pdf format and printer button report viewer is not responding on the click what i can do i need to use this button and print out the report pls tell me correct solution

    Monday, December 11, 2006 1:45 PM
  • I was using update panel of ajax thats why the print dialog box was not appearing .

    after remove the update panel the dialog box appear but when i select  all or page selection then the report is not appearing in pdf format instead the error message is appearing

    " Failed to export using the options you specified. Please check your options and try again. "

    pls tell me anybody what is the problem

    Monday, December 18, 2006 7:55 AM
  • Hi Basim,

    I am facing exactly the same problem.

    [1] am also using Session to store the reportDocument and retrieving it when PostBack occur.

    [2]I was also using AJAX Update Panel and only if when I removed it , i was getting "Print" or "export" pop ups.

    [3]I am also getting exactly the same message when i try to export or print.

     

    I am sorry, i can not resolve any problem.But in case you find our solutions, then please let me know.

    Thanks,

    Vijay

     

    Sunday, November 25, 2007 11:28 PM
  • Well I just had the exact same problem, " Failed to export using the options you specified. Please check your options and try again. ", but the posts above made me able to resolve it.

    Here's the solution:
    What I did was when binding the dataset to the report I add the report to the session like below:
    Dim oRpt As New CrystalReport1()
    oRpt.SetDataSource(objOffertesDS)
    CrystalReportViewer1.ReportSource = oRpt
    Session.Add("report", oRpt)
    In my Page_Load event sub I also put:

    CrystalReportViewer1.ReportSource = Session("report")
    Just like you guys said. This is working for me in every aspect that I wanted it to work, which are:
    - Still seeing the data in the report after postback
    - Export to every type ( i tested them all )
    - Print to PDF

    I don't know why this doesn't work for you guys, but I'm using VS 2008 & CRP 2008.

    I realise this post is 2 years later, but it might still help somebody.
    Wednesday, November 18, 2009 11:23 AM
  • Thanks Yannick, it is 4.5 years later and your solution came in extremely handy!
    Sunday, July 24, 2011 4:42 PM