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

Ajax Grid not exporting to excel

1 Answer 59 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Help
Top achievements
Rank 1
Help asked on 20 Apr 2017, 03:25 PM

I understand that a Ajax grid exporting to excel must be handled differently. In my research I found there are two ways to accomplish this. The only the remotely works is this

Adding this Javascript to the aspx page

                Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(initRequest);
                function initRequest(sender, args) {
                    if (args.get_postBackElement().id.indexOf("btnExportGrid") != -1) {
                        args.set_cancel(true);  //stop async request
                        sender._form["**EVENTTARGET"].value = args.get_postBackElement().id.replace(/\_/g, "$");
                        sender._form["**EVENTARGUMENT"].value = "";
                        sender._form.submit();
                        return;
                    }
                }

 

The problem is I get the following Javascript error

0x800a138f - JavaScript runtime error: Unable to set property 'value' of undefined or null reference

 

If I hit continue the grid exports. if I comment line out I get same error on the next line. I comment that out the export does not work.

1 Answer, 1 is accepted

Sort by
0
Vessy
Telerik team
answered on 21 Apr 2017, 07:19 AM
Hi,

It seems that the sender._form["**EVENTTARGET"] object is not available at the time when you are trying to access its value. Can you, please, try the approaches given in the following code library and see whether the problem persists?
http://www.telerik.com/support/code-library/export-radgrid-content-to-excel-word-csv-pdf-with-ajax-enabled

Please note, also, that if you are using a version of the controls later than 2016 Q1, the default built-in export buttons are already performing regular postback, therefore it is not needed to manually exclude them from Ajax, even the RadGrid control is ajaxified, to perform export with them. You can find useful information on this matter here:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/how-to/Exporting/export-from-ajaxified-grid

Regards,
Vessy
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Help
Top achievements
Rank 1
Answers by
Vessy
Telerik team
Share this question
or