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

Radgrid Export to Excel Refresh Required?

20 Answers 429 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 18 Jun 2013, 06:12 PM
Hi All,

I have a standard Radgrid and am using the RadGrid.MasterTableView.ExportToExcel() method.  Unfortunately, I have to refresh the page, after an export, in order to do any sorting/filtering or another export.  Am I missing something?

Thanks,
Mark

20 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 Jun 2013, 05:08 AM
Hi Mark,

I'm not sure what is causing that issue,Please have a look at this code snippet.

ASPX:
<telerik:RadGrid ID="RadGrid1" AllowPaging="True" runat="server"
    AutoGenerateColumns="false" AllowSorting="True" onitemcommand="RadGrid1_ItemCommand">          
   <MasterTableView CommandItemDisplay="Top">
     <CommandItemSettings ShowExportToExcelButton="true" />
        <Columns>
            <telerik:GridBoundColumn DataField="FirstName" HeaderText="First Name"> </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

C#:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
 if (e.CommandName == RadGrid.ExportToExcelCommandName)
  {
    RadGrid1.ExportSettings.ExportOnlyData = true;
    RadGrid1.ExportSettings.IgnorePaging = true;
    RadGrid1.ExportSettings.OpenInNewWindow = false;
  }
}

Thanks,
Shinu
0
Mark
Top achievements
Rank 1
answered on 19 Jun 2013, 01:29 PM
Shinu,

Thanks for the reply!

It's actually all C# and fired off of a link button.  I have tried using the CommandItemSettings method as well with the same results.  Does this have something to do with Ajax?  Another interesting note is that in either case RadGrid1.ExportingSettings.OpenInNewWindow must be set to true otherwise it will not export at all.

Thanks,
Mark
0
Princy
Top achievements
Rank 2
answered on 20 Jun 2013, 12:54 PM
Hi Mark,

Please try the following code snippet.Hope this helps you.

ASPX:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
 <ClientEvents OnRequestStart="onRequestStart"></ClientEvents>
<AjaxSettings>
    <telerik:AjaxSetting AjaxControlID="RadGrid1">
        <UpdatedControls>
            <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
        </UpdatedControls>
    </telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadGrid ID="RadGrid1" runat="server"   OnItemCommand="RadGrid1_ItemCommand1"
    AllowSorting="true" >
 <MasterTableView AutoGenerateColumns="False" DataKeyNames="OrderID" CommandItemDisplay="Top">
     <CommandItemSettings ShowExportToExcelButton="true" ShowAddNewRecordButton="false" ShowRefreshButton="true" />
       . . . . . . .
 </MasterTableView>
</telerik:RadGrid>

JS:
<script type="text/javascript">
 function onRequestStart(sender, args)
 {
   if (args.get_eventTarget().indexOf("ExportTo") >= 0)
  {
    args.set_enableAjax(false);
  }
 }
</script>

Thanks,
Princy
0
Mark
Top achievements
Rank 1
answered on 20 Jun 2013, 01:49 PM
Princy,

I actually removed the ajax manager because it appears to slow the solution down significantly.  Radgrid response time was improved noticeably.  I can re-implement it, but I would prefer to avoid it if at all possible.

Thanks,
Mark
0
Kostadin
Telerik team
answered on 21 Jun 2013, 08:54 AM
Hi Mark,

Note that the exporting feature works only with regular postbacks. This means, that the asynchronous postback should be canceled when performing an export.

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
Mark
Top achievements
Rank 1
answered on 25 Jun 2013, 03:05 PM
Kostadin,

I have tried firing off the export to excel via a link button (C#) and using the Command Item Settings button as well.  Both appears to have the same effect.  Essentially the grid is unusable until the page is refreshed after the export. 

Thanks,
Mark
0
Mark
Top achievements
Rank 1
answered on 27 Jun 2013, 08:49 PM
I have re-implemented the RadAjaxManager as well as adding the following javascript to the page.

JS:
<script type="text/javascript">
 function onRequestStart(sender, args)
 {
   if (args.get_eventTarget().indexOf("ExportTo") >= 0)
  {
    args.set_enableAjax(false);
  }
 }
</script>

It is definitely getting added and the radgrid is definitely ajaxified, but I am still experiencing the same issue.  I can export once and then the radgrid becomes unresponsive until the page is refreshed.

I have even reviewed the following link, and my work is very similar.
http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/exporting/defaultcs.aspx

Thanks,
Mark
0
Kostadin
Telerik team
answered on 28 Jun 2013, 07:31 AM
Hi Mark,

I would ask you to provide us with a code declaration of the problematic page and the related code behind. This way we will be able to investigate the issue locally and provide you with more to the point answer. 

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
Mark
Top achievements
Rank 1
answered on 28 Jun 2013, 01:45 PM
Here is some of the code:

Here is the script that is embedded on the page it is added in the prerender method,  When I view source it is included on the page.
private string EmbeddedScriptFormat =
                    "<script type=\"text/javascript\">" + Environment.NewLine +
                        "function onRequestStart(sender, args)" + Environment.NewLine +
                        "{" + Environment.NewLine +
                            "if (args.get_eventTarget().indexOf(\"ExportTo\") >= 0)" + Environment.NewLine +
                            //"if(args.get_eventTarget().indexOf(\"lbExportToExcel\") >= 0)" + Environment.NewLine +
                            "{" + Environment.NewLine +
                                "args.set_enableAjax(false);" + Environment.NewLine +
                            "}" + Environment.NewLine +
                        "}" + Environment.NewLine +
                    "</script>";

This is added in the create child controls method in order to associate the RadGrid with the RadAjaxManager.
//Ajaxifying the Radgrid
this.AjaxManager.ClientEvents.OnRequestStart = "onRequestStart";
    AjaxSetting ajaxSetting = new AjaxSetting();
    ajaxSetting.AjaxControlID = this.rgTest.ID;
        AjaxUpdatedControl ajaxUpdatedControl = new AjaxUpdatedControl();
        ajaxUpdatedControl.ControlID = this.rgTest.ID;
    ajaxSetting.UpdatedControls.Add(ajaxUpdatedControl);
this.AjaxManager.AjaxSettings.Add(ajaxSetting);

The Export to Excel function is called through a C# LinkButton.

The RadAjaxManager is setup in the OnInit method.  Please let me know if you need more code.

Thanks,
Mark
0
Kostadin
Telerik team
answered on 03 Jul 2013, 06:39 AM
Hello Mark,

Could you please confirm that the export functionality works as expected when the ajax is disabled? Additionally could you please make sure that the ajax is disabled properly by onRequestStart function? The provided code looks correct so I will need the entire code declaration and code behind of the page for further investigation.

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
Mark
Top achievements
Rank 1
answered on 03 Jul 2013, 02:36 PM
The export functionality works the same way [page refresh required after export] regardless of whether Ajax is enabled.  I test this by adding/removing the RadAjaxManager in code.  The RadGrid status bar either animates or does not animate based upon whether Ajax is enabled.  This is all done in C#, in a SharePoint 2010 Web Part, so there is no aspx.  The onRequestStart script is added during PreRender via a ClientScriptManager.  The RadAjaxManager is set up during OnInit.

How would I got about testing whether onRequestStart actually disabled Ajax properly?  I do see the function on the page when I view source.

Here is the Export To Excel link button code if it is helpful:
void lbExportToExcel_Click(object sender, EventArgs e)
{
    if (this.chbxExportPaging.Checked)
    {
        this.rgTest.ExportSettings.IgnorePaging = true;
    }
    else
    {
        this.rgTest.ExportSettings.IgnorePaging = false;
    }
    this.rgTest.ExportSettings.OpenInNewWindow = true;
    this.rgTest.ExportSettings.ExportOnlyData = true;
    this.rgTest.ExportSettings.Excel.Format = GridExcelExportFormat.ExcelML;
    this.rgTest.MasterTableView.ExportToExcel();
}

Thanks,
Mark
0
Kostadin
Telerik team
answered on 08 Jul 2013, 06:58 AM
Hi Mark,

You could add a break point or write a debugger; into your javascript function. Check out the following code snippet.
private string EmbeddedScriptFormat =
                    "<script type=\"text/javascript\">" + Environment.NewLine +
                        "function onRequestStart(sender, args)" + Environment.NewLine +
                        "{ debugger;" + Environment.NewLine +
                            "if (args.get_eventTarget().indexOf(\"ExportTo\") >= 0)" + Environment.NewLine +
                            //"if(args.get_eventTarget().indexOf(\"lbExportToExcel\") >= 0)" + Environment.NewLine +
                            "{" + Environment.NewLine +
                                "args.set_enableAjax(false);" + Environment.NewLine +
                            "}" + Environment.NewLine +
                        "}" + Environment.NewLine +
                    "</script>";

This way you will be able to check whether the ajax is disabled or not.

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
Mark
Top achievements
Rank 1
answered on 08 Jul 2013, 02:53 PM
Interesting, it looks like the export link button is not calling the onRequestStart Function.  The arrow buttons for paging through the Radgrid do, however.  I will look into this further.

Thanks!
0
Srinivas
Top achievements
Rank 1
answered on 08 Oct 2013, 12:58 PM
   Thank you......Shinnu
0
Mark
Top achievements
Rank 1
answered on 21 Oct 2013, 02:15 PM
Finally fixed it!  I had to implement the 3rd workaround in this link.  Here it is just to make life simpler:

Add the following script to your webpart / custom control:

<script type="text/javascript" language="javascript">
 
    //sharepoint postback to work after clicking on telerik export to pdf
    if (typeof (_spBodyOnLoadFunctionNames) != 'undefined' && _spBodyOnLoadFunctionNames != null) {
        _spBodyOnLoadFunctionNames.push("supressSubmitWraper");
    }
 
    function supressSubmitWraper() {
        _spSuppressFormOnSubmitWrapper = true;
    }
    
</script>

-Mark
0
Ken
Top achievements
Rank 1
answered on 25 Aug 2015, 11:16 PM

Thanks Mark, I used the 3rd option in your referenced link and that worked like a charm!

For the benefit of anyone else reading this post, we faced this issue when using in 2015 Q1 version of Telerik suite of controls.

NOTE: I'm not saying that this is an issue with the Telerik suite of controls, but just specifying my operating environment for the benefit of those reading this post...

Raj

0
Sameer
Top achievements
Rank 1
answered on 20 Apr 2016, 07:14 AM

The Export to excel functionality which is successfully working in all browsers is getting failed in Edge browser for some reason,

Iam using RadGrid.MasterTableView.ExportToExcel() ..

Can some one figure out what could be the issue

0
Rob
Top achievements
Rank 1
answered on 22 Apr 2016, 04:02 PM

Well, what if you're not in SharePoint and you need to refresh the page after exporting?  Here's what works for me:

function OnClientClose(oWnd, args) {
    //get the transferred arguments
    if (oWnd.get_name() == 'RadExportWindow' && args) {
        document.getElementById('<%= hdnExport.ClientID %>').value = args._argument.ExportText;
        setTimeout('ForcePostback();', 5000);
        __doPostBack('', 'Export');
    }
    return false
}
 
function ForcePostback() {
    __doPostBack('', 'Refresh');
}

 

0
Daniel
Telerik team
answered on 22 Apr 2016, 04:19 PM
Hello Samir,

Have you tried to reproduce the issue on the online demos?
Export to Excel demo

If you believe you have found a bug you can submit a regular support ticket with a sample project so that we can debug it locally.

Regards,
Daniel
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Syed Ali
Top achievements
Rank 1
answered on 26 Nov 2016, 11:06 AM

Mark, your solution finalliy worked for me as welll.

<script type="text/javascript" language="javascript">

    //sharepoint postback to work after clicking on telerik export to pdf
    if (typeof (_spBodyOnLoadFunctionNames) != 'undefined' && _spBodyOnLoadFunctionNames != null) {
        _spBodyOnLoadFunctionNames.push("supressSubmitWraper");
    }

    function supressSubmitWraper() {
        _spSuppressFormOnSubmitWrapper = true;
    }

</script>

Thanks,

Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Mark
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Kostadin
Telerik team
Srinivas
Top achievements
Rank 1
Ken
Top achievements
Rank 1
Sameer
Top achievements
Rank 1
Rob
Top achievements
Rank 1
Daniel
Telerik team
Syed Ali
Top achievements
Rank 1
Share this question
or