Im trying to open print dialog box on client and server side without using Reportviewer..It works for IE,Chrome and Safari but it doesn't work in Firefox..
Thanks..
Here is my test code:
End the server side code:
Thanks..
Here is my test code:
<!DOCTYPE html>
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<
title
></
title
>
<
telerik:RadCodeBlock
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
ReportViewer.prototype.PrintReport = function()
{
this.PrintAs("Default");
}
function MyPrint()
{
<%=ReportViewer1.ClientID %>.PrintReport();
}
</
script
>
</
telerik:RadCodeBlock
>
<
script
type
=
"text/javascript"
>
ReportViewer.OnReportLoadedOld = ReportViewer.OnReportLoaded;
ReportViewer.prototype.OnReportLoaded = function () {
this.OnReportLoadedOld();
var printButton = document.getElementById("PrintButton");
printButton.disabled = false;
}
</
script
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
asp:ScriptManager
runat
=
"server"
/>
<
div
>
<
asp:Button
ID
=
"Button1"
runat
=
"server"
Text
=
"Print"
OnClick
=
"Button1_Click"
Style
=
"width: 41px"
/>
<
asp:Button
ID
=
"PrintButton"
runat
=
"server"
Text
=
"Print Dialog Server"
OnClick
=
"PrintButton_Click"
/>
<
asp:Button
ID
=
"PrintClient"
runat
=
"server"
Text
=
"Print Client"
OnClientClick
=
"MyPrint(); return false;"
/>
<
telerik:ReportViewer
ID
=
"ReportViewer1"
runat
=
"server"
Width
=
"100%"
Height
=
"800px"
Style="display:none"></
telerik:ReportViewer
>
</
div
>
</
form
>
</
body
>
</
html
>
End the server side code:
public
partial
class
Default : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
Telerik.Reporting.InstanceReportSource instanceReportSource =
new
Telerik.Reporting.InstanceReportSource();
instanceReportSource.ReportDocument =
new
Report1();
this
.ReportViewer1.ReportSource = instanceReportSource;
}
protected
void
Button1_Click(
object
sender, EventArgs e)
{
ExportToPDF(
new
Report1());
}
void
ExportToPDF(Telerik.Reporting.Report reportToExport)
{
ReportProcessor reportProcessor =
new
ReportProcessor();
Telerik.Reporting.InstanceReportSource instanceReportSource =
new
Telerik.Reporting.InstanceReportSource();
instanceReportSource.ReportDocument = reportToExport;
Telerik.Reporting.Processing.RenderingResult result = reportProcessor.RenderReport(
"PDF"
, instanceReportSource,
null
);
string
fileName = result.DocumentName +
"."
+ result.Extension;
Response.Clear();
Response.ContentType = result.MimeType;
Response.Cache.SetCacheability(HttpCacheability.Private);
Response.Expires = -1;
Response.Buffer =
true
;
Response.AddHeader(
"Content-Disposition"
,
string
.Format(
"{0};FileName=\"{1}\""
,
"attachment"
,
fileName));
Response.BinaryWrite(result.DocumentBytes);
Response.End();
}
protected
void
PrintButton_Click(
object
sender, EventArgs e)
{
string
printScript =
string
.Format(
"{0}.PrintReport();"
,
this
.ReportViewer1.ClientID);
this
.ClientScript.RegisterStartupScript(
this
.GetType(),
"ReportPrint"
, printScript,
true
);
}
}