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

Open print dialog by asp button..(Problem in Firefox)

1 Answer 165 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Veysel
Top achievements
Rank 1
Veysel asked on 29 Nov 2012, 05:53 PM
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:
<!DOCTYPE html>
 
<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);
        }
    }

1 Answer, 1 is accepted

Sort by
0
Veysel
Top achievements
Rank 1
answered on 29 Nov 2012, 06:01 PM
Ok I figured out the problem..firefox doesnt show the dialog box because the report viewer's display is set to none...so I removed that and put report viewer inside a div which has 1px width and height..so it works now..
Tags
General Discussions
Asked by
Veysel
Top achievements
Rank 1
Answers by
Veysel
Top achievements
Rank 1
Share this question
or