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

Export to Excel Using an Iframe

15 Answers 490 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kyle
Top achievements
Rank 1
Kyle asked on 13 Jun 2013, 04:25 PM
Hi All

My Layout is as follows:

Master Page (ScriptManager)
Content Page
  DropDownList
  RadDock
    asp:Panel
       UserControl (ascx)
           iFrame (ifmExcel)
           RadGrid

We have ajax settings so that the dropdownlist refreshes the user controls.  We would like to maintain this.  

The way I got the export to work with a REPEATER was using :

System.IO.

 

StringWriter stringWrite = new System.IO.StringWriter();

 

System.Web.UI.

 

HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);         

 

myRepeater.RenderControl(htmlWrite);

 

 

Session[

 

"ExportBody"] = stringWrite.ToString();

 

ifmExcel.Attributes.Add(

 

"src", "GenerateDownload.aspx");

The GenerateDownload would process the body and response.write as normal.

Is there something similiar we can do for the radgrid to have it loaded in an iframe or what's the best way to go about exporting the data?

I saw the render control for the rad grid, but if we can get it to use the export settings for the binary format in this setup that would be ideal.

Thanks in advanced.

 

15 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 18 Jun 2013, 11:21 AM
Hi Kyle,

I would recommend you to use the build in export functionality of the grid. You could do that by simply call one of the MasterTableView's export methods ExportToExcel(), ExportToWord(), ExportToPdf(), ExportToCsv(). Check out the following code snippet.
RadGrid1.MasterTableView.ExportToExcel();
RadGrid1.MasterTableView.ExportToWord();
RadGrid1.MasterTableView.ExportToCsv();
RadGrid1.MasterTableView.ExportToPdf();

Regards,
Kostadin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Kyle
Top achievements
Rank 1
answered on 19 Jun 2013, 01:52 PM
Hi Kostadin,


I've tried using the following:
 
        FillrgSearch(true);
        rgSearch.ExportSettings.IgnorePaging = true;
        rgSearch.ExportSettings.OpenInNewWindow = true;
        rgSearch.MasterTableView.ExportToExcel();


The behavior is as follows

1)  The control shows the loading panel similar to a postback or update request.
2)  After a time the control comes back allowing us to switch search criteria or attempt the export again.
3)  No file is sent.


Please keep in mind the hierarchy of the controls.  Also please note that each control is wrapped in it's own ajax panel:

<telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel1" LoadingPanelID="Loading1">                
     <asp:Panel ID="pnlUC1" runat="server" style="max-height:300px;">        
               <uc:SS runat="server" ID="UC1"></uc:SS>  <!-- RADGRID to export in UC1 -->
         </asp:Panel>
</telerik:RadAjaxPanel>
0
Kyle
Top achievements
Rank 1
answered on 19 Jun 2013, 02:14 PM
Hi Kostadin,


I've tried using the following:
 
     
FillrgSearch(true);
rgSearch.ExportSettings.IgnorePaging = true;
rgSearch.ExportSettings.OpenInNewWindow = true;
rgSearch.MasterTableView.ExportToExcel();



The behavior is as follows:

1)  The control shows the loading panel similar to a postback or update request.
2)  After a time the control comes back allowing us to switch search criteria or attempt the export again.
3)  No file is sent.


Please keep in mind the hierarchy of the controls.  Also please note that each control is wrapped in it's own ajax panel:

 <telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel1" LoadingPanelID="Loading1">            
     
 <asp:Panel ID="pnlUC1" runat="server" style="max-height:300px;">                      
            <uc:SS runat=
"server" ID="UC1"></uc:SS>  <!-- RADGRID to export in UC1 -->          
    </asp:Panel>  
  </telerik:RadAjaxPanel>


It seems as though the export isn't working in this case.  Please suggest what we can do.
0
Kyle
Top achievements
Rank 1
answered on 19 Jun 2013, 02:16 PM
It seems as though the export isn't working in this case.  Please suggest what we can do.  My apologies for the double post, the forum was having an issue posting all of this in one for some reason.

0
Kostadin
Telerik team
answered on 24 Jun 2013, 08:06 AM
Hi Kyle,

Note that the build-in exporting feature works only with regular postbacks. Additional information could be found at the following help article.

Regards,
Kostadin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Kyle
Top achievements
Rank 1
answered on 24 Jun 2013, 04:04 PM
Hi Kostadin,

I'm attempting to use this example to export from an ajaxified grid by registering the button as a postback control.   If I use a normal button, the control registers fine, but doesn't follow the behavior of a normal post back.

If I use :
          <MasterTableView TableLayout="Auto" AllowMultiColumnSorting="false">
          <CommandItemSettings ShowExportToExcelButton="true"></CommandItemSettings> 

The export button doesn't show, so I can't find it to register the control.

and if I try:
       StringBuilder sb = new StringBuilder();
       System.IO.StringWriter stringWrite = new System.IO.StringWriter(sb);
       System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
       rgSearch.RenderControl(htmlWrite);

It throws errors about the column headers needing runat="server" for the gridviewlinkcolumns.


There's gotta be a way to do this.  I can do this with a repeater, but would really prefer to use the telerik grid.


0
Kostadin
Telerik team
answered on 27 Jun 2013, 10:03 AM
Hello Kyle,

Thank you for getting back to us.

In order to display the export button you have to enable the CommandItem by setting CommandItemDisplay property. Then you could get the button by using the following approach.
protected void Page_PreRender(object sender, EventArgs e)
    {
        Button pdfButton = (RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0] as GridCommandItem).FindControl("ExportToExcelButton") as Button;
    }

I hope this information helps.

Regards,
Kostadin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Kyle
Top achievements
Rank 1
answered on 17 Jul 2013, 03:55 PM
Hi Kostadin,

I'm sorry for the late reply . . . had an urgent project come up that needed attention.

I'm still having issues with this:

1)  In the multi page view I'm using the renderSelectedPageOnly="true" and the button can only be found when the grid is actually rendered.  For now I've added it to the rgOpenTickets_NeedDataSource:

if (rgOpenTickets.MasterTableView.GetItems(GridItemType.CommandItem).ToList().Count > 0)
        {
            Button b = (rgOpenTickets.MasterTableView.GetItems(GridItemType.CommandItem)[0]).FindControl("ExportToExcelButton") as Button;
            ScriptManager.GetCurrent(this.Parent.Parent.Page).RegisterPostBackControl(b);
        }


I've forced this and confirmed that the button is being registered, however the grid doesn't export when the button is clicked.

I also tried using the tab pre_render, but when I click the command in the grid, nothing is exported.

    protected void RadTabStrip1_PreRender(object sender, EventArgs e)
    {
        if (rgOpenTickets.MasterTableView.GetItems(GridItemType.CommandItem).ToList().Count > 0)
        {
            Button b = (rgOpenTickets.MasterTableView.GetItems(GridItemType.CommandItem)[0]).FindControl("ExportToExcelButton") as Button;
            ScriptManager.GetCurrent(this.Parent.Parent.Page).RegisterPostBackControl(b);
        }

    }

Thanks in advanced.
0
Kostadin
Telerik team
answered on 22 Jul 2013, 08:13 AM
Hello Kyle,

I was not able to reproduce the issue on my side, so I prepared a small sample and attached it to this forum post. Please give it a try and let me know how it differs from your real setup.

Regards,
Kostadin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Kyle
Top achievements
Rank 1
answered on 22 Jul 2013, 03:11 PM
Hi Kostadin,

The project you created just had a page.  

We have a
master control -> web page -> user control  

hierarchy.


I have setup a test project, is there a way I can email it to you as the forum won't let me post it?

Edit:

After doing a little research found you guys will download from a public FTP.

It can be found here:
http://rapidshare.com/files/2774132766/Test.zip
0
Kyle
Top achievements
Rank 1
answered on 22 Jul 2013, 03:22 PM
Hi Kostadin,

The project you created just had a page.  

We have a
master control -> web page -> user control  

hierarchy.


I have setup a test project, is there a way I can email it to you as the forum won't let me post it?

Edit:

After doing a little research found you guys will download from a public FTP.

It can be found here:
http://rapidshare.com/files/2774132766/Test.zip

The default page is a bit more complex with different user controls & dock zones, but for simplicity's sake this is a stripped down version that has each type of control used.  You should also be able to reproduce the issue of not being able to export the grid.

Thanks for everything.
0
Accepted
Kostadin
Telerik team
answered on 25 Jul 2013, 07:16 AM
Hi Kyle,

First of all I would recommend you to remove the RadAjaxLoading which wraps the user control where the grid is located and add an ajax setting in the RadAjaxManager to update the grid. Check out the following code snippet.
<telerik:RadAjaxManager runat="Server" EnableAJAX="true" ID="RadAjaxManager1" ClientEvents-OnResponseEnd="reloadTabs" ClientEvents-OnRequestStart="requestStart">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="ddlDays">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="pnlTestControl" LoadingPanelID="Loading1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="pnlTestControl">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="pnlTestControl" LoadingPanelID="Loading1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>

Then I would suggest you to disable the ajax by wiring the OnRequestStart event of the ajax manager.
function requestStart(sender, args) {
            if (args.get_eventTarget().indexOf("ExportToExcel") > 0) {
                args.set_enableAjax(false);
            }
        }

Additionally I modified your sample and attached it to this forum post.

Regards,
Kostadin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Kyle
Top achievements
Rank 1
answered on 25 Jul 2013, 04:26 PM
Hi Kostadin,

Thanks for the efforts. I've downloaded the most recent example but have yet to manage to get the desired results.

I also tried to use the following code:

protected void rgTest_ItemCommand(object sender, GridCommandEventArgs e)
  {
      if (e.CommandName == RadGrid.ExportToExcelCommandName)
      {
          rgTest.ExportSettings.IgnorePaging = true;
          rgTest.MasterTableView.ExportToExcel();
      }
  }

I still don't get the save dialog box.  Please advise.
0
Kostadin
Telerik team
answered on 30 Jul 2013, 10:29 AM
Hi Kyle,

It is not necessary to explicitly call ExportToExcel()  method as it is already been fired. Could you please try removing the ajax at all and check whether the export works properly? If it does, that I would suggest you to debugged the requestStart JavaScript function and check whether the ajax is disabled when export command is fired.

Regards,
Kostadin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Kyle
Top achievements
Rank 1
answered on 31 Jul 2013, 03:29 PM
Hi Kostadin,

Thanks very much.  I didn't realize you needed both the javascript function as well as wiring up the client events to it in the ajaxmanager.  After adding the function everything is working as it should.  Thanks very much for the help!
Tags
Grid
Asked by
Kyle
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Kyle
Top achievements
Rank 1
Share this question
or