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

Rendering a report directly into a RadWindow

1 Answer 187 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
T. Stanley
Top achievements
Rank 1
T. Stanley asked on 22 Nov 2009, 05:47 PM

Hi.  I just got my license to Telerik Reporting and am excited to use it in my website in place of the SQL Reporting Services that I have used to now.

My site generates numerous reports to be printed on the client computer.  I use a window.open script to popup a single ReportRendering.aspx page to which I send report ID and parameters (parameters in a Session variable).  The page uses Response methods to stream the rendered report from the SQL Reporting engine.  I would like to replicate this process using Telerik Reporting.  So I created a page 'reportpage.aspx' that is empty except for the following code behind:

 

public partial class reporting_reportpage : System.Web.UI.Page  
{  
    protected void Page_Load(object sender, EventArgs e)  
    {  
        Telerik.Reporting.Report MyReport = new Telerik.Reporting.Report();  
        MyReport = (Telerik.Reporting.Report)Session["taljacreport"];  
        ExportToPDF(MyReport);  
    }  
 
    void ExportToPDF(Telerik.Reporting.Report reportToExport)  
    {  
        ReportProcessor reportProcessor = new ReportProcessor();  
        RenderingResult result = reportProcessor.RenderReport("PDF", reportToExport, null);  
 
        Response.Clear();  
        Response.ContentType = result.MimeType;  
        Response.Cache.SetCacheability(HttpCacheability.Private);  
        Response.Expires = -1;  
        Response.Buffer = true;  
        Response.BinaryWrite(result.DocumentBytes);  
        Response.End();  
    }      
}  
 

 
On a test page, I put a RadWindow, a test buton, and a javascript function to open the RadWindow:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TelerikTestForm.aspx.cs" Inherits="TelerikTestForm" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml">  
<head runat="server">  
    <title></title>  
</head> 
<body> 
    <form id="form1" runat="server">  
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server" /> 
 
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">  
            <script type="text/javascript">  
                function PopUpReport() {  
                    var wnd = window.radopen("reporting/reportpage.aspx", "rdwReport");  
                    return false;  
                }  
            </script> 
        </telerik:RadCodeBlock> 
          
        <div> 
            <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> 
        </div> 
 
        <telerik:RadWindowManager ID="rwmReport" runat="server" > 
            <Windows> 
                    <telerik:RadWindow ID="rdwReport" runat="server" Width="850px" Height="1100px" Modal="true" VisibleStatusbar="False"   
                        Behaviors="Move,Close" Left="" NavigateUrl="" Top="" > 
                    </telerik:RadWindow> 
            </Windows> 
        </telerik:RadWindowManager> 
 
    </form> 
</body> 
</html> 
 

On the test page's code-behind, I put the following:

public partial class TelerikTestForm : System.Web.UI.Page   
{  
    protected void Page_Load(object sender, EventArgs e)  
    {  
    }  
 
    protected void Button1_Click(object sender, EventArgs e)  
    {  
        Report myreport = new userdirectory();  
        myreport = ReportMethods.AddReportParameters(myreport, null);  
        Session["taljacreport"] = myreport;  
//        ClientScript.RegisterClientScriptBlock(this.GetType(), "openreport", "var wnd=window.open('reporting/reportpage.aspx', '_blank', 'height=1100,width=850,directories=no,status=no,titlebar=no,toolbar=no,menubar=no,location=no');", true);  
//        ClientScript.RegisterClientScriptBlock(this.GetType(), "openreport", "var wnd = window.radopen('reporting/reportpage.aspx', 'rdwReport'); return false;", true);  
        ClientScript.RegisterClientScriptBlock(this.GetType(), "openreport", "PopUpReport()", true);  
    }  
}  
 

The 'ReportMethods.AddReportParameters() method is one I wrote to append parameters bot the report class by parsing a concatenated string (none are needed for this report).

Note that I have three lines of ScriptBlock execution for opening the rendering page in a browser popup or in the RadWindow.  The first, with the browser popup works, but neither of the last two do, either writing the radopen script directly (nothin happens) or via the script function (script object reference error on 'PopUpReport()'.  I imagine that this is just my poor understanding of scripting the RadWindow, but I am stuck.  I would really like to use the RadWindow since it is so good on all the browsers.  If anyone could shed some light on this for me, I would be grateful.  Thank you!

Thomas Stanley

1 Answer, 1 is accepted

Sort by
0
Accepted
Georgi Tunev
Telerik team
answered on 25 Nov 2009, 09:16 AM
Hi Thomas,

Here is one way to call the JavaScript properly:

protected void Button1_Click(object sender, EventArgs e)
{
    //Report myreport = new userdirectory();
    //myreport = ReportMethods.AddReportParameters(myreport, null);
    //Session["taljacreport"] = myreport;
    //        ClientScript.RegisterClientScriptBlock(this.GetType(), "openreport", "var wnd=window.open('reporting/reportpage.aspx', '_blank', 'height=1100,width=850,directories=no,status=no,titlebar=no,toolbar=no,menubar=no,location=no');", true); 
    //        ClientScript.RegisterClientScriptBlock(this.GetType(), "openreport", "var wnd = window.radopen('reporting/reportpage.aspx', 'rdwReport'); return false;", true); 
     
    string script = "function f(){PopUpReport(); Sys.Application.remove_load(f);}; Sys.Application.add_load(f);";
    ClientScript.RegisterStartupScript(this.GetType(), "openreport", script, true);
}

More information on the subject is available in this blog post:
http://blogs.telerik.com/blogs/posts/09-05-05/executing_javascript_function_from_server-side_code.aspx

I also noticed that you have set a very high value for the Height property - that is why I would suggest to set the KeepInScreenBounds property of the RadWindowManager to true. This will ensure that when the window is shown, its toolbar will be visible in the viewport.


Best wishes,
Georgi Tunev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
General Discussions
Asked by
T. Stanley
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
Share this question
or