Export RadGrid content to Excel/Word/CSV/PDF with Ajax enabled

Thread is closed for posting
11 posts, 0 answers
  1. 63F75A2C-1F16-4AED-AFE8-B1BBD57646AD
    63F75A2C-1F16-4AED-AFE8-B1BBD57646AD avatar
    1572 posts
    Member since:
    Oct 2004

    Posted 04 Apr 2007 Link to this post

    Requirements

    RadControls version

    RadGrid, RadAjax
    or
    RadControls for ASP.NET AJAX Q1 2008

    .NET version

    2.0 / 3.x

    Visual Studio version

    2005 / 2008

    programming language

    JavaScript, VB.NET, C#

    browser support

    all browsers supported by RadControls


      PROJECT DESCRIPTION
    The demo presents how to export the grid content to Excel/Word/CSV/PDF when:
    • RadGrid resides inside RadAjaxPanel
    • RadGrid is ajaxified through RadAjaxManager
    • The RadGrid AJAX mode is enabled and the export action is triggered from buttons residing in the grid body (RadGrid Classic only, the built-in AJAX is removed from RadGrid Prometheus)

    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/ajax manager or the grid itself, determine whether the target control is ajaxified and explicitly disable its ajax mode to export with regular postback. Below is the main part of the code:

    <script type="text/javascript"
        function mngRequestStarted(ajaxManager, eventArgs) 
        { 
            if (eventArgs.get_eventTarget().indexOf("mngBtn") != -1) 
                eventArgs.set_enableAjax(false); 
        } 
    </script> 
  2. C7498A83-7E2E-418C-8791-93EF573A7569
    C7498A83-7E2E-418C-8791-93EF573A7569 avatar
    9934 posts
    Member since:
    Nov 2016

    Posted 05 Apr 2007 Link to this post

    Hello guys,

    In addition to the previous post, I am attaching another project presenting how to export to Excel/Word when the grid resides in content page and is ajaxified through RadAjaxManager located in the Master page. The difference is that the OnRequestStart handler has to be placed in the master page aspx and the ajax manager settings should be added either:

    • using RadAjaxManagerProxy in the content page to append the ajax settings to the manager declaratively (RadAjax Prometheus only)
    • dynamically from the code-behind of the master page
    Best,
    Stephen
    the telerik team

    Instantly find answers to your questions at the new telerik Support Center
  3. 7E1365B8-CC8E-4BBF-96FA-6E76D73EDD4D
    7E1365B8-CC8E-4BBF-96FA-6E76D73EDD4D avatar
    7 posts
    Member since:
    Jun 2007

    Posted 20 Sep 2007 Link to this post

    What if radGrid resides in content page and is ajaxified by simplying setting the radGrid's EnableAJAX="True"?
  4. C7498A83-7E2E-418C-8791-93EF573A7569
    C7498A83-7E2E-418C-8791-93EF573A7569 avatar
    9934 posts
    Member since:
    Nov 2016

    Posted 20 Sep 2007 Link to this post

    Hi Simon,

    I guess that the sample for the first grid instance in the first project in this thread will be applicable when the control resides in content page and its built-in Ajax mechanism is switched on. Let me know if I am leaving something out.

    Regards,
    Stephen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. 7E1365B8-CC8E-4BBF-96FA-6E76D73EDD4D
    7E1365B8-CC8E-4BBF-96FA-6E76D73EDD4D avatar
    7 posts
    Member since:
    Jun 2007

    Posted 20 Sep 2007 Link to this post

    Hi Stephen,

    Based on the project description (i.e. 1st zip file), the requirements are
    • RadGrid resides inside RadAjaxPanel
    • RadGrid is ajaxified through RadAjaxManager
    May be I'm missing something as well, in order to Ajaxified my radGrid, I did not add RadAjaxpanel and RadAjaxManager controls to the page. I just turn on the flag!
  6. 7E1365B8-CC8E-4BBF-96FA-6E76D73EDD4D
    7E1365B8-CC8E-4BBF-96FA-6E76D73EDD4D avatar
    7 posts
    Member since:
    Jun 2007

    Posted 20 Sep 2007 Link to this post

    It works now after I upgraded RadGrid to the latest version i.e. 5.0

    Thanks.
  7. B26BDE21-BDD5-4F88-9088-EC7D5539D6D1
    B26BDE21-BDD5-4F88-9088-EC7D5539D6D1 avatar
    162 posts
    Member since:
    Feb 2007

    Posted 21 Sep 2007 Link to this post

    I'm not sure if new version v 5.0 has a bug but earlier versions worked fine in my case:

    I export grid to i.e. Excel with Ajax enabled="false" and if I set Grid1.ExportSettings.IgnorePaging = True I always get such an error:

    RegisterRequiresControlState can only be called before and during PreRender

    Switching this property to false doesn't cause mentioned error. Any idea?

    Regards,
        Rycho
  8. C7498A83-7E2E-418C-8791-93EF573A7569
    C7498A83-7E2E-418C-8791-93EF573A7569 avatar
    9934 posts
    Member since:
    Nov 2016

    Posted 24 Sep 2007 Link to this post

    Hi Rycho,

    I tried to recreate the problem using the latest version 5.0.0 of RadGrid but my attempts were not successful (see the attached project). Can you please outline the differences between my test case and yours or modify the demo to reproduce the erroneous behavior? They can identify the cause of the issue you experience to address it accordingly.

    Best regards,

    Stephen

    the Telerik team


    Instantly find answers to your questions at the new Telerik Support Center
  9. 3BD6F94B-4C03-46D3-8568-9982F1F201BF
    3BD6F94B-4C03-46D3-8568-9982F1F201BF avatar
    10940 posts
    Member since:
    May 2014

    Posted 23 Oct 2007 Link to this post

    Hi guys,

    We just wanted to let you know, that we've added one more project to show you how to export from withing MS UpdatePanel, when the control is in RadGridTemplateColumn or in the CommandItemTemplate. Avoiding ajaxification from MS UpdatePanel is easy considering the control in question is available directly on the page by setting it declaratively as PostBackTrigger. However when in Template control, you cannot do that declaratively and need to locate and access it on the server. According to the MS AJAX documentation adding PostBackTrigger control programmatically is not supported, however you can use the RegisterPostBackControl() method of the ScriptManager for this purpose. Here is the code we've used in the example:

        protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)  
        {  
            if (e.Item is GridDataItem)  
            {  
                Button btn = (e.Item as GridDataItem)["TemplateColumn"].FindControl("Button1"as Button;  
                ScriptManager1.RegisterPostBackControl(btn);  
            }  
            if (e.Item is GridCommandItem)  
            {  
                Button btncmd = (e.Item as GridCommandItem).FindControl("btnExcel"as Button;  
                ScriptManager1.RegisterPostBackControl(btncmd);  
     
                btncmd = (e.Item as GridCommandItem).FindControl("btnWord"as Button;  
                ScriptManager1.RegisterPostBackControl(btncmd);  
     
                btncmd = (e.Item as GridCommandItem).FindControl("btnCSV"as Button;  
                ScriptManager1.RegisterPostBackControl(btncmd);  
     
                btncmd = (e.Item as GridCommandItem).FindControl("btnPDF"as Button;  
                ScriptManager1.RegisterPostBackControl(btncmd);  
            }  
        } 


    Best regards,
    Steve
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  10. 3BD6F94B-4C03-46D3-8568-9982F1F201BF
    3BD6F94B-4C03-46D3-8568-9982F1F201BF avatar
    10940 posts
    Member since:
    May 2014

    Posted 15 Jan 2008 Link to this post

    Hi Rycho,

    We're adding one more project that is somehow related to the Export/RadGrid/Ajax scenario that this code library covers - namely exporting RadGrid's content from context RadMenu which is ajax enabled. Since the export requires standard postback, we have to somehow disable the ajax only for the specific menu items which trigger the export and keep the ajax for the rest.
    This is easily achieved by using the menu item's value to check against the appropriate one. As usual sample project is attached to show you our implementation.

    Best regards,
    Steve
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  11. 55399722-08F4-4C16-B02F-AF2E96DF6AC2
    55399722-08F4-4C16-B02F-AF2E96DF6AC2 avatar
    4949 posts
    Member since:
    Jan 2017

    Posted 27 Jul 2009 Link to this post

    Hello guys,

    Note that we updated the sample projects, attached to this code-library thread.
    - we removed the obsolete client-side methods - for example, we replaced EnableAjax with set_enableAjax().
    - we simplified the javascript code and optimized it to cover more scenarios.

    Regards,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.