locked
Crystal Report Export and Print button not working inside UpdatePanel RRS feed

  • Question

  • User1591997341 posted

    Hi

    Iuse UpdatePanel for my pages, clients requested to view pages without flickering.

    So, I put all component in update panel, but after that, export and printing for Crystal Reports stoped to work. If I put report viewer outside of updatepanel its working.

    Have anyone this problem? There's some solution for this?

    Thanks, Paul

    Thursday, November 16, 2006 7:33 AM

All replies

  • User-576999009 posted
    yeah, same problem here, anyone has a solution yet? Thanks.
    Friday, March 2, 2007 12:18 PM
  • User879354489 posted

    i donno much abt update panel.. but hope this information might be helpful for u..

    Viewstate should be enabled for the page where u r placing viewer..(Enableviewstate= true in page directive).. if its not enabled then print and download options will not work properly..

    Saturday, March 3, 2007 2:28 AM
  • User-1634733559 posted

    i have same prob and that solution dosnt work

    [:)] pls i need help

    Thursday, December 6, 2007 6:40 PM
  • User1506028751 posted

    How about using an IFrame?
    I had the same problem & solved it using an IFrame.
    It might not be the best solution, but it works.

    Monday, April 21, 2008 7:46 AM
  • User-1052012207 posted

    Hi,

     I had the same problem. I ended up disabling CrystalReportViewer's toolbars and I created my own button that displayed the report as PDF in new window. And if I remember correctly, the button would have to be outside the update panel and use some JavaScript.

     


     

    Monday, April 21, 2008 5:26 PM
  • User-1130287460 posted

    exactly....

    i also did this as klin6on said. when a button clicks a new window will pop up and displays the report in pdf format. if u want like this i'll give you the code....

    dim rpt as new reportdocument  

     rpt.ExportToDisk(ExportFormatType.PortableDocFormat, Server.MapPath("~/Export/Personnel.pdf"))
    Dim popupscript As String = "<script language='javascript'>" + "window.open('Export/Personnel.pdf');</script>"
    Page.ClientScript.RegisterStartupScript(Me.GetType(), "PopUpWindow", popupscript, False)

    Tuesday, April 22, 2008 1:48 AM
  • User1506028751 posted

    Hi,

    I applied the idea of joseabie.
    It was a good idea, but there were some issues:
    Using the same file path for all reports might conflict with different reports.
    Even using different file names will be a problem because then the export directory will keep growing.
    How would you like to know with which files are not being used so you can remove them?
    Another issue is that the page reloads unnecessarily.

    This is how I solved the problem(C#):

    I created a page which contains my report which returns report files in an HttpResponse at the page load with the following code:

    PrintPDF.aspx.cs:

    ReportDocument rpt = CrystalReportSource1.ReportDocument;
    rpt.SetParameterValue(
    "@paramater1", Request.Params["parameter1"]);
    rpt.SetParameterValue(
    "@parameter2", Request.Params["parameter2"]);
    rpt.ExportToHttpResponse(CrystalDecisions.Shared.
    ExportFormatType.PortableDocFormat, Response, true, "ReportName");

    Then instead of linking the popup script to the click method I used the following code in the load event of the button so I can keep it in the updatepanel:

    CrystalReport.aspx.cs:

    Button
    printButton = (Button)sender;
    string path = PrintPDF.aspx?parameter1=value1&parameter2=value2");
    string script = String.Format("window.open('{0}')", path);
    printButton.Attributes.Add(
    "onclick", script);

    Please let me know if it is not clear.

    Jafar

    Tuesday, April 22, 2008 4:48 AM
  • User-774343849 posted

    I think this is the easiest way (for me at least)

    You need two pages, myPage.aspx and OpenFile.aspx

     
    Code extract myPage.aspx

     

            private ReportDocument rd;

    private void CreateCrystalReport()
    {
    rd.SetParameterValue("MyField", "MyValue");

    /*export to pdf*/
    ExportOptions expo = rd.ExportOptions;
    expo.ExportDestinationType = ExportDestinationType.DiskFile;
    expo.ExportFormatType = ExportFormatType.PortableDocFormat;
    expo.DestinationOptions = new DiskFileDestinationOptions();

    string fileName = "report";
    string filePath = @"~/tmpStorage/" + fileName;

    rd.ExportToDisk(ExportFormatType.PortableDocFormat, Server.MapPath(filePath + ".pdf"));

    Session["reportDocument"] = rd;

    string script = "<script language='javascript'> window.open('OpenFile.aspx?action=401&filepath=" + filePath + "&filename=" + fileName + "');</script>";

    ScriptManager.RegisterStartupScript(this, typeof(myPage), "PopupCP", script, false);

    }
     

     Code extract OpenFile.aspx

     

        public partial class OpenFile : System.Web.UI.Page
    {
    private ReportDocument rd;
    protected void Page_Load(object sender, EventArgs e)
    {
    this.Unload += new EventHandler(OpenFile_Unload);

    string action = string.Empty;
    if (Request["action"] != null)
    action = Request["action"];

    if (action == "401")
    CreatePdfResponseFor401();
    }

    void OpenFile_Unload(object sender, EventArgs e)
    {
    //remember to clean up
    if (rd != null)
    {
    rd.Close();
    rd.Dispose();
    Session["reportDocument"] = null;
    GC.Collect();
    }
    }

    private void CreatePdfResponseFor401()
    {
    string filePath = Request["filepath"];
    string fileName = Request["filename"];

    if (filePath == null)
    throw new ArgumentNullException("error message");

    if (fileName == null)
    throw new ArgumentNullException("error message");

    rd = Session["reportDocument"] as ReportDocument;

    if(rd == null)
    {
    throw new ArgumentNullException("error message");
    }

    rd.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, fileName);
    }
    }

      

    -a- 

    Wednesday, April 30, 2008 2:52 AM
  • User808215256 posted
    it's so complicated, try this... " <asp:UpdatePanel ID="UpdatePanel1" runat="server"> " " <Triggers >" " <asp:PostBackTrigger ControlID="CrystalReportViewer1" /> " " </Triggers> " " <ContentTemplate > " " <CR:CrystalReportSource ID="CrystalReportSource1" runat="server"> " " <Report FileName="YouReportName.rpt">" " <DataSources> " " ....you Data here, etc." " </DataSources>" " </Report>" " </CR:CrystalReportSource>" " </ContentTemplate >" and you CrystalReportViewer1 work normaly. So simple.
    Wednesday, January 21, 2009 9:37 AM
  • User-799496382 posted

    Here is the soluction.You just need to Trigger the  CrystalReportViewer.

     

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
              
                <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server"
                    DisplayGroupTree="False" oninit="CrystalReportViewer1_Init" />
                     </ContentTemplate>
                     <Triggers> <asp:PostBackTrigger ControlID="CrystalReportViewer1"/></Triggers>
                </asp:UpdatePanel>

    Tuesday, March 3, 2009 7:37 AM
  • User497575847 posted

    wowwwwwww........

    Thanks Punnanthomas....

    it solved out all ma headache of over a month........



    I had to simply place the trigger just at the end of update panel.... like

    <Triggers> <asp:PostBackTrigger ControlID="CrystalReportViewer1"/></Triggers>
                </asp:UpdatePanel>


    Thanks a lot......

    Swadesh

    Saturday, June 27, 2009 5:49 AM
  • User-976597021 posted

     This works. I wanted it to be more complicated, but alas...it is this simple. Thanks for posting this answer.

    Thursday, July 23, 2009 3:45 PM
  • User-939458312 posted

     I am using Master Page  here is what worked for me on the Report page

    ScriptManager scriptManager = ScriptManager.GetCurrent(this);

    scriptManager.RegisterPostBackControl(this.reportRunner);

    this will disable ajax for the crystal report viewer.

    Monday, August 10, 2009 2:30 PM
  • User1877228370 posted

    It works beautifull.

    This way should be preferred instead of <Trigger>....</Trigger>, simply because it covers more cases.

    If, as it happened to me, CrystalReportViewer1 is placed inside a TabContainer, which is inside an UpdatePanel, then there are problems with getting "ControlID" for setting the <Trigger> section.

    Instead, handling ScriptManager is more elegant and more efficient (...in my case :) ).

    Thanx a lot!

    Thursday, November 26, 2009 9:42 AM
  • User709641232 posted

    where should this code be placed?

    Wednesday, December 9, 2009 8:55 PM
  • User1877228370 posted

    On CS (C#):

    protected void Page_Load(object sender, EventArgs e)
    {
            ScriptManager scriptManager = ScriptManager.GetCurrent(this);

            scriptManager.RegisterPostBackControl(this.CrystalReportViewer1);       
            ............
           

    ...while in aspx there is something like:

    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
           
    <asp:UpdatePanel ID="upd" runat="server">
          <ContentTemplate>
                  ...........
                  <ajaxToolkit:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0">
                      <ajaxToolkit:TabPanel ID="TabPanel2" runat="server">
                                <HeaderTemplate>
                                    InterfacePageData
                                </HeaderTemplate>
                                <ContentTemplate>                               
                                    <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server"
                                        .... />                               
                                   
                                </ContentTemplate>
                            </ajaxToolkit:TabPanel>
                 </ajaxToolkit:TabContainer>
         </ContentTemplate>
    </asp:UpdatePanel>

    Saturday, December 12, 2009 5:07 AM
  • User-1540341547 posted

    thanks punnanthomas this is the best answer

    <Triggers> <asp:PostBackTrigger ControlID="CrystalReportViewer1"/></Triggers>

    Hany SheblCool

    S.Developer

    Monday, December 14, 2009 1:24 PM
  • User-955612810 posted

    I have found another solution


    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler); function BeginRequestHandler(sender, args) { // disable Ajax for Prinr and Export button of Crystal Report Viewer if(typeof(document.activeElement) != 'undefined' && (document.activeElement.title == "Export" || document.activeElement.title == "Print")) { e.EnableAjax = false; } }


    Wednesday, December 23, 2009 6:43 AM
  • User-1213451322 posted

    paul i have same problem like urs..

    if have any suggestion, pls inform me.

    thanks...

    Thursday, February 11, 2010 7:46 AM
  • User-266628817 posted

    Hello Jafar2,

    I have same problem.

    Crystal Report Export and Print button not working inside UpdatePanel

    So how can i do this??? If it is possible than tell me code which will help in my project.

    Actually i want functionality of my reports like when i press next button my page (my main page where my reports is generated conditionally)  will not going to be post back & press on export button (of crystal report viewer) pop up the window to choose file format.

     

    Thanks in advance.

    Ronak

    Thursday, May 19, 2011 2:46 AM
  • User-2082463482 posted

    This is what works for me..

     

    Set your UpdatePanel's UpdateMode to Conditional.  Then set a postback trigger to the button you use to begin your report exporting/printing.  The full postback is a necessity since the response cannot be modified during an async postback. 

     

    <asp:UpdatePanel ID="updatePanel" runat="server" UpdateMode="Conditional">
            <Triggers>
                <asp:PostBackTrigger ControlID="btnPrint" />
            </Triggers>
            <ContentTemplate>
    
    
    <asp:Button ID="btnPrint" runat="server" Text="Print" Width="72px" />
    
            </ContentTemplate>
    </asp:UpdatePanel>

    Tuesday, May 24, 2011 9:23 AM
  • User-444119553 posted

    Has anyone seen a fix for this. I'm experiencing the same issue. The export and print buttons on my Crystal Report Toolbar inside a modal popup will not print the report. It will only close the modal

    Friday, July 29, 2011 12:26 PM
  • User-444119553 posted

    Nevermind , the postback trigger was all I needed

    <Triggers> <asp:PostBackTrigger ControlID="crvProviderPrintResults"/></Triggers>
                </asp:UpdatePanel>

    Friday, July 29, 2011 12:53 PM