Radgrid Export to Excel Refresh Required?

21 posts, 0 answers
  1. Mark
    Mark avatar
    127 posts
    Member since:
    May 2013

    Posted 18 Jun 2013 Link to this post

    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
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 19 Jun 2013 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mark
    Mark avatar
    127 posts
    Member since:
    May 2013

    Posted 19 Jun 2013 Link to this post

    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
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 20 Jun 2013 Link to this post

    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
  6. Mark
    Mark avatar
    127 posts
    Member since:
    May 2013

    Posted 20 Jun 2013 Link to this post

    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
  7. Kostadin
    Admin
    Kostadin avatar
    1713 posts

    Posted 21 Jun 2013 Link to this post

    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.
  8. Mark
    Mark avatar
    127 posts
    Member since:
    May 2013

    Posted 25 Jun 2013 Link to this post

    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
  9. Mark
    Mark avatar
    127 posts
    Member since:
    May 2013

    Posted 27 Jun 2013 Link to this post

    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
  10. Kostadin
    Admin
    Kostadin avatar
    1713 posts

    Posted 28 Jun 2013 Link to this post

    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.
  11. Mark
    Mark avatar
    127 posts
    Member since:
    May 2013

    Posted 28 Jun 2013 Link to this post

    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
  12. Kostadin
    Admin
    Kostadin avatar
    1713 posts

    Posted 03 Jul 2013 Link to this post

    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.
  13. Mark
    Mark avatar
    127 posts
    Member since:
    May 2013

    Posted 03 Jul 2013 Link to this post

    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
  14. Kostadin
    Admin
    Kostadin avatar
    1713 posts

    Posted 08 Jul 2013 Link to this post

    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.
  15. Mark
    Mark avatar
    127 posts
    Member since:
    May 2013

    Posted 08 Jul 2013 Link to this post

    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!
  16. Srinivas
    Srinivas avatar
    4 posts
    Member since:
    Oct 2013

    Posted 08 Oct 2013 Link to this post

       Thank you......Shinnu
  17. Mark
    Mark avatar
    127 posts
    Member since:
    May 2013

    Posted 21 Oct 2013 Link to this post

    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
  18. Ken
    Ken avatar
    13 posts
    Member since:
    Nov 2014

    Posted 25 Aug 2015 in reply to Mark Link to this post

    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

  19. Sameer
    Sameer avatar
    1 posts
    Member since:
    Apr 2016

    Posted 20 Apr Link to this post

    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

  20. Rob
    Rob avatar
    115 posts
    Member since:
    Aug 2012

    Posted 22 Apr Link to this post

    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');
    }

     

  21. Daniel
    Admin
    Daniel avatar
    4946 posts

    Posted 22 Apr Link to this post

    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.
  22. Syed Ali
    Syed Ali avatar
    1 posts
    Member since:
    Mar 2014

    Posted 26 Nov Link to this post

    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,

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017