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

problem with radwindow calling parent window's method to export radgrid using ajax

2 Answers 40 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Aaron
Top achievements
Rank 1
Aaron asked on 04 Nov 2009, 04:43 PM
Hey guys,
Here's the situation.
I have a radgrid with a dropdown box with different ways to export the grid data that also triggers a confirm type form to pop up.
The form asks the user if they want to perform other tasks before exporting: yes or no, then the window is closed and sends an AJAX request to perform either option. But in both cases, although the export method is hit, nothing gets exported. I have had the grid wrapped in an AJAXPanel and not but it hasn't made a difference.
Please help! Thank you
Aaron

function exportGrid() {  
            $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("ExportGrid");  
        }     
 
 
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">  
            <AjaxSettings>  
                <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">  
                    <UpdatedControls>  
                        <telerik:AjaxUpdatedControl ControlID="rgAcctTrans" />  
                    </UpdatedControls>  
                </telerik:AjaxSetting>  
            </AjaxSettings>  
        </telerik:RadAjaxManager>  
 
           protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)  
        {  
 if (e.Argument == "ExportGrid")  
            {  
                try 
                {  
                    string dateExtension = string.Empty;  
                    string to = string.Empty;  
                    string from = string.Empty;  
                    if ((dpFrom.SelectedDate.HasValue) || (dpTo.SelectedDate.HasValue))  
                    {  
                        if (dpTo.SelectedDate.HasValue)  
                            to = dpTo.SelectedDate.Value.ToString("dd.MM.yyyy");  
                        if (dpFrom.SelectedDate.HasValue)  
                            from = dpFrom.SelectedDate.Value.ToString("dd.MM.yyyy");  
                        dateExtension += "." + from + "-" + to;  
                    }  
                    if ((dpBilledFrom.SelectedDate.HasValue) || (dpBilledTo.SelectedDate.HasValue))  
                    {  
                        if (dpBilledFrom.SelectedDate.HasValue)  
                            from = dpBilledFrom.SelectedDate.Value.ToString("dd.MM.yyyy");  
                        if (dpBilledTo.SelectedDate.HasValue)  
                            to = dpBilledTo.SelectedDate.Value.ToString("dd.MM.yyyy");  
                        dateExtension += ".Billed-" + from + "-" + to;  
                    }  
 
 
                    rgAcctTrans.ExportSettings.ExportOnlyData = false;  
                    rgAcctTrans.ExportSettings.FileName = "Transactions" + dateExtension;  
                    rgAcctTrans.ExportSettings.IgnorePaging = true;  
                    rgAcctTrans.ExportSettings.OpenInNewWindow = false;  
 
                    rgAcctTrans.Columns[0].HeaderStyle.HorizontalAlign = HorizontalAlign.Left;  
                    rgAcctTrans.Columns[0].ItemStyle.HorizontalAlign = HorizontalAlign.Left;  
                    rgAcctTrans.Columns[1].HeaderStyle.HorizontalAlign = HorizontalAlign.Right;  
                    rgAcctTrans.Columns[1].ItemStyle.HorizontalAlign = HorizontalAlign.Right;  
                    //rgAcctTrans.Rebind();  
 
                    switch (ddlExportTo.SelectedValue)  
                    {  
                        case "Excel":  
                            {  
                                rgAcctTrans.MasterTableView.ExportToExcel();  
                                break;  
                            }  
                        case "Word":  
                            {  
                                rgAcctTrans.MasterTableView.ExportToWord();  
                                break;  
                            }  
                        case "CSV":  
                            {  
                                rgAcctTrans.MasterTableView.ExportToCSV();  
                                break;  
                            }  
                    }  
                      
                    ddlExportTo.Items[0].Selected = true;  
                }  
                catch (Exception ex)  
                {  
                    lblMessage.Text = "An error has occurred. <br/> " + ex.Message;  
                } 
            }
        } 

2 Answers, 1 is accepted

Sort by
0
Accepted
Sebastian
Telerik team
answered on 05 Nov 2009, 03:11 PM
Hi Aaron,

First, if you ajaxified the grid via RadAjaxManager, you do not need to wrap it inside RadAjaxPanel because the manager will embed the grid in such on-the-fly. Additionally, note that  you need to disable the ajax explicitly on export operation as explained in this topic from the grid documentation (see the code library example linked in it as well).

Best regards,
Sebastian
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
Aaron
Top achievements
Rank 1
answered on 06 Nov 2009, 06:13 PM
Thanks Sebastian!
It works perfectly now!
Tags
Ajax
Asked by
Aaron
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Aaron
Top achievements
Rank 1
Share this question
or