This is a migrated thread and some comments may be shown as answers.

PrintReport not working with AJAX

12 Answers 223 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Per
Top achievements
Rank 1
Per asked on 12 Oct 2011, 12:47 PM
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

12 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 17 Oct 2011, 05:24 PM
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.

0
Per
Top achievements
Rank 1
answered on 17 Oct 2011, 06:00 PM
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
0
Chavdar
Telerik team
answered on 20 Oct 2011, 01:49 PM
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.

0
Per
Top achievements
Rank 1
answered on 23 Oct 2011, 09:21 PM
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);

0
David
Top achievements
Rank 1
answered on 25 May 2012, 07:10 PM
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

0
Emad
Top achievements
Rank 1
answered on 28 Mar 2016, 10:24 AM

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

0
Stef
Telerik team
answered on 28 Mar 2016, 12:50 PM
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
0
Emad
Top achievements
Rank 1
answered on 28 Mar 2016, 02:12 PM

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

0
Emad
Top achievements
Rank 1
answered on 28 Mar 2016, 02:35 PM

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

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

 

Thanks,

Emad

0
Stef
Telerik team
answered on 29 Mar 2016, 02:54 PM
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
0
Emad
Top achievements
Rank 1
answered on 29 Mar 2016, 03:04 PM

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

 

0
Stef
Telerik team
answered on 29 Mar 2016, 03:30 PM
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
Tags
General Discussions
Asked by
Per
Top achievements
Rank 1
Answers by
Peter
Telerik team
Per
Top achievements
Rank 1
Chavdar
Telerik team
David
Top achievements
Rank 1
Emad
Top achievements
Rank 1
Stef
Telerik team
Share this question
or