PrintReport not working with AJAX

13 posts, 0 answers
  1. Per
    Per avatar
    116 posts
    Member since:
    Jan 2008

    Posted 12 Oct 2011 Link to this post

    Hi!

    I have page with the following controls:
    A textbox
    A submit button
    A label
    A ReportViewer

    The page is using telerik ajax and is setup so that when a user clicks on the submit button, the label and the reportviewer is updated.
    Now when the user clicks the submit button, the following code is run:
    ReportViewer1.Report = new MyReport();
    var printScript = String.Format("{0}.PrintReport();", ReportViewer1.ClientID);
       ScriptManager.RegisterStartupScript(this, this.GetType(), "ReportPrint", printScript, true);

    The problem where is that the javascript will run before the ajax has rendered the reportviewer and that gives my an error.

    So my question is, how can I print the report, using AJAX, when the reportviewer is inside a AJAX update panel?

    Regards
    Per

  2. Peter
    Admin
    Peter avatar
    1611 posts

    Posted 17 Oct 2011 Link to this post

    Hello Per,

    Generally our suggestion is to enable your print button on ReportViewer.prototype.OnReportLoaded as shown in the following help article. Give it a try and if you still experience any difficulties we will appreciate if you elaborate on the error and open a support thread and send us a sample project that shows the problematic behavior to debug on our end. 

    Greetings,
    Peter
    the Telerik team

    Q2’11 SP1 of Telerik Reporting is available for download (see what's new). Get it today.

  3. DevCraft banner
  4. Per
    Per avatar
    116 posts
    Member since:
    Jan 2008

    Posted 17 Oct 2011 Link to this post

    Hi and tanks for your reply. In my case, I want to print the report as soon as it is finished rendering. Is there any OnReportRendered event that I can use? At the moment, the PrintReport function is executed before the report viewer has finished rendering the report :( Regards, Per
  5. Chavdar
    Admin
    Chavdar avatar
    898 posts

    Posted 20 Oct 2011 Link to this post

    Hello Per,

    It will be best if you can open a support ticket and send to us a runnable project so that we can check directly what the problem is and try to suggest a solution for it. Generally speaking you should be able to achieve your goal by using the ReportViewer.prototype.OnReportLoaded function which is called right after the report is shown in the viewer.

    All the best,
    Chavdar
    the Telerik team

    Q2’11 SP1 of Telerik Reporting is available for download (see what's new). Get it today.

  6. Per
    Per avatar
    116 posts
    Member since:
    Jan 2008

    Posted 23 Oct 2011 Link to this post

    Hi

    I was aboe to solve my problem using the following code.
    Hope this helps someone else :)

    var printScript = "";
    printScript += "ReportViewer.OnReportLoadedOld = ReportViewer.OnReportLoaded;";
    printScript += "ReportViewer.prototype.OnReportLoaded = function()";
    printScript += "{";
    printScript += ReportViewer1.ClientID + ".PrintReport();";
    printScript += "ReportViewer.OnReportLoaded = ReportViewer.OnReportLoadedOld;";
    printScript += "}";
     
    ScriptManager.RegisterStartupScript(this, GetType(), "ReportPrint", printScript, true);

  7. David
    David avatar
    9 posts
    Member since:
    Aug 2011

    Posted 25 May 2012 Link to this post

    Hello
    I had the same problem in one of my pages and your solution worked...

    But i noticed that for the report it fails the reportPageUrl, basePrintUrl,exportUrl are not having any values.  hence when in the printreport it does not print anything...

    I have another page where the reportViewer1.PrintReport()... works fine.... when i traded in to the javascript this instance had those values.

    Can someone clarify why this happened for me to better understand it.
    Thanks

  8. Emad
    Emad avatar
    16 posts
    Member since:
    Dec 2015

    Posted 28 Mar Link to this post

    Hello,

    I have almost slimier case.

    I have page have textbox, button and reportviewer (in hidden div, display:none)

    I want to pass parameter to report then print it.

    I'm using ReportViewer not HTML5 ReportViewer

    Note : report is created direct in root folder under TelerikWebApp3 folder

    Could you please share a sample javascript code to pass parameter and print

    I need it only from client side not server side.

     

    also I have tried it using HTML5 reportviewer ans success to pass parameter but not able to print as PrintReport is not working with html5 reportviewer !!!

     

    Thanks,

    Emad

  9. Stef
    Admin
    Stef avatar
    3036 posts

    Posted 28 Mar Link to this post

    Hello Emad,

    If you want to print reports at the client without displaying them in a viewer, please check the Direct Client Side Printing - Error forum thread.

    I hope this information is helpful.

    Regards,
    Stef
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  10. Emad
    Emad avatar
    16 posts
    Member since:
    Dec 2015

    Posted 28 Mar in reply to Stef Link to this post

    Hello Stef,

    Thank you for reply, but unfortunately my issue still not solved.

    Can you please share a code how to pass parameter to report viewer from client side then print from client side as well.

    Assume parameter name is VISIT_ID

     

    Regards,

    Emad

  11. Emad
    Emad avatar
    16 posts
    Member since:
    Dec 2015

    Posted 28 Mar in reply to Emad Link to this post

    <%=ReportViewer1.ClientID %>.PrintReport();                

    this working fine for printing, but before I call it I need to pass parameter then refresh report viewer

     

    Thanks,

    Emad

  12. Stef
    Admin
    Stef avatar
    3036 posts

    Posted 29 Mar Link to this post

    Hi Emad,

    The old ASP.NET WebForms ReportViewer can be updated only at the server. In code-behind you can get the viewer's ReportSource and update its Parameters collection. The ReportSource.Parameters collection is mapped by key (Name) to the wrapped report's ReportParameters collection.

    Once the viewer is refreshed from code-behind, you can call the viewer's PrintReport Javascript method.


    The above scenario is fully supported by the HTML5 Viewer which is a JS/CSS/HTML based widget. Consider the example in How To: Pass Values to Report Parameters. Also the HTML5 Viewer's API allows you to control the viewer client-side.

    Regards,
    Stef
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  13. Emad
    Emad avatar
    16 posts
    Member since:
    Dec 2015

    Posted 29 Mar Link to this post

    Hi Stef,

     

    thank you you for reply, yes I'm able to pass parameter to new html5 report viewer from client side, but I'm not able to print from outside button from client side code!!

     

     

    thanks,

    Emad

     

  14. Stef
    Admin
    Stef avatar
    3036 posts

    Posted 29 Mar Link to this post

    Hi Emad,

    The HTML5 Viewer's API is exposed and you can use the viewers commands to execute print, export, navigation, refresh and other operations.

    For example check:
    Regards,
    Stef
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
DevCraft banner