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

RadAjaxManager, RadGrid and Exporting

4 Answers 250 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Casey
Top achievements
Rank 1
Casey asked on 03 Nov 2009, 02:17 PM
Hello,

I'm having issues with exporting to Excel or PDF when the user clicks on a linkbutton in the commanditemtemplate of RadGrid1. The RadGrid appears to refresh, and then is completely loaded without paging enabled. The commanditemdisplay is not displaying anymore either (I display the commanditems based on access levels). I can fix this issue by removing RadGrid1 from the UpdateControls part of RadAjaxManager1; however, I need RadGrid1 to be updated when there is an ajaxRequest initiated by closing a Radwindow. Here is my code related to this issue. Please let me know how I can achieve exporting to Excel and PDF while keeping RadGrid1 in the RadAjaxManager1 updated controls section. I put a breakpoint on RadAjaxManager1_AjaxRequest, but it was never hit.

Thanks,
Casey

RadAjaxManager1:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" 
                                OnAjaxRequest="RadAjaxManager1_AjaxRequest">  
            <AjaxSettings> 
                <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">  
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="DateTime" /> 
                        <telerik:AjaxUpdatedControl ControlID="RadGrid2" /> 
                        <telerik:AjaxUpdatedControl ControlID="lblNote" /> 
                        <telerik:AjaxUpdatedControl ControlID="Note" /> 
                        <telerik:AjaxUpdatedControl ControlID="RequiredFieldValidator1" /> 
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> 
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
                <telerik:AjaxSetting AjaxControlID="RadGrid2">  
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="lblNote" /> 
                        <telerik:AjaxUpdatedControl ControlID="Note" /> 
                        <telerik:AjaxUpdatedControl ControlID="RequiredFieldValidator1" /> 
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
            </AjaxSettings> 
        </telerik:RadAjaxManager> 

Javascript to initiate ajaxRequest:
function refreshGrid() {  
            $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("Rebind");  
        } 

Code-Behind executed onAjaxRequest:
protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)  
    {  
        if (e.Argument.ToString() == "Rebind")  
        {  
            foreach (GridDataItem i in RadGrid2.Items)  
            {  
                if (i.Selected)  
                {  
                    SqlDataSource3.Insert();  
                    i.Selected = false;  
                }  
            }  
            RequiredFieldValidator1.Enabled = false;  
            RadGrid1.Rebind();  
        }  
    } 

RadGrid1:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False"   
                 GridLines="None" Skin="Office2007" ItemStyle-Wrap="true"   
                 DataSourceID="SqlDataSource1" oninit="RadGrid1_Init" 
                 AllowSorting="True" onitemcreated="RadGrid1_ItemCreated"   
                 AllowFilteringByColumn="True" AllowPaging="True" Width="100%"   
                 OnItemDataBound="RadGrid1_ItemDataBound">  
<ItemStyle Wrap="True"></ItemStyle> 
 
<MasterTableView CellSpacing="-1" DataSourceID="SqlDataSource1"   
                 AllowSorting="true" 
                 CommandItemDisplay="None" ItemStyle-Wrap="true">  
 
<ItemStyle Wrap="True"></ItemStyle> 
    <CommandItemTemplate> 
    <table width="100%">  
    <tr> 
    <td align="right">  
        <asp:LinkButton ID="Excel" runat="server" Font-Bold="True"   
                        CausesValidation="False" Height="10px" 
                        OnClick="Excel_Click">Export to Excel</asp:LinkButton> 
                        &nbsp;&nbsp;&nbsp;  
        <asp:LinkButton ID="PDF" runat="server" Font-Bold="True" 
                        CausesValidation="False" Height="10px" 
                        OnClick="PDF_Click">Export to PDF</asp:LinkButton> 
    </td> 
    </tr> 
    </table> 
    </CommandItemTemplate> 
<Columns> 
...  
</Columns> 
</MasterTableView> 
</telerik:RadGrid> 

LinkButton CodeBehind:
    protected void Excel_Click(object sender, EventArgs e)  
    {  
        ConfigureExport();  
        RadGrid1.MasterTableView.ExportToExcel();  
    }  
    protected void PDF_Click(object sender, EventArgs e)  
    {  
        ConfigureExport();  
        RadGrid1.ExportSettings.Pdf.PageWidth = Unit.Pixel(1500);  
        RadGrid1.MasterTableView.ExportToPdf();  
    }  
    public void ConfigureExport()  
    {  
        RadGrid1.ExportSettings.ExportOnlyData = true;  
        RadGrid1.ExportSettings.IgnorePaging = true;  
        RadGrid1.ExportSettings.OpenInNewWindow = true;  
    } 

4 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 03 Nov 2009, 02:36 PM
Hello Casey,

Generally speaking, the exporting feature of the control work with regular postbacks only. The reason is the grid prepares additional information when performing export operation (available on postback). When the action is performed through asynchronous requests, this information can not be passed through the XMLHttpObject - that is why the communication between the browser and the server fails.

To bypass the limitation you can wire the OnRequestStart event of the ajax panel or ajax manager, determine whether the target control is ajaxified and explicitly disable its ajax mode to export with regular postback.
Please find more information in the following help article:
Export from ajaxified grid

I hope this information helps.

All the best,
Pavlina
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.
0
Casey
Top achievements
Rank 1
answered on 03 Nov 2009, 02:57 PM
Pavlina,

Thank you for your reply. This approach is not working for some reason. I do not think that there is an AjaxRequest initiated by clicking on the linkbuttons in the command item template because the RadAjaxManager1_AjaxRequest server side method is never hit when I put a breakpoint on it. RadGrid1 does not initiate an AjaxRequest. RadGrid1 is only affected by Ajax when I call the javascript function after closing a RadWindow. Here is what I changed my code to, based on the link provided.

Thanks,
Casey

        function onRequestStart(sender, args) {  
            if (args.get_eventTarget().indexOf("Excel") >= 0)  
                args.set_enableAjax(false);  
        } 

I tried both: ClientEvents-OnRequestStart="onRequestStart" and ClientEvents-OnRequestStart="onRequestStart()"
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" 
                                OnAjaxRequest="RadAjaxManager1_AjaxRequest" 
                                ClientEvents-OnRequestStart="onRequestStart">  
            <AjaxSettings> 
                <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">  
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="DateTime" /> 
                        <telerik:AjaxUpdatedControl ControlID="RadGrid2" /> 
                        <telerik:AjaxUpdatedControl ControlID="lblNote" /> 
                        <telerik:AjaxUpdatedControl ControlID="Note" /> 
                        <telerik:AjaxUpdatedControl ControlID="RequiredFieldValidator1" /> 
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> 
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
                <telerik:AjaxSetting AjaxControlID="RadGrid2">  
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="lblNote" /> 
                        <telerik:AjaxUpdatedControl ControlID="Note" /> 
                        <telerik:AjaxUpdatedControl ControlID="RequiredFieldValidator1" /> 
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
            </AjaxSettings> 
        </telerik:RadAjaxManager> 
0
Casey
Top achievements
Rank 1
answered on 03 Nov 2009, 03:54 PM
Pavlina - I was able to get the approach recommended in the link to work by adding the below to the RadAjaxManager1 settings.

<telerik:AjaxSetting AjaxControlID="RadGrid1">  
      <UpdatedControls> 
             <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> 
      </UpdatedControls> 
</telerik:AjaxSetting> 

Thanks,
Casey
0
Pavlina
Telerik team
answered on 03 Nov 2009, 05:52 PM
Hello Casey,

I am glad to hear that you managed to solve the problem! In case you experience any other problems or you have additional questions, do not hesitate to contact us again!

Kind regards,
Pavlina
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
Grid
Asked by
Casey
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Casey
Top achievements
Rank 1
Share this question
or