Skip Navigation LinksHome / Community & Support / Code Library / ASP.NET and ASP.NET AJAX > General and Integration Projects > Export RadGrid content to Excel/Word/CSV/PDF with Ajax enabled

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

Feed from this thread
  • Posted on Apr 4, 2007 (permalink)

    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> 

  • Sebastian Sebastian admin's avatar

    Posted on Apr 5, 2007 (permalink)

    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

  • slai avatar

    Posted on Sep 20, 2007 (permalink)

    What if radGrid resides in content page and is ajaxified by simplying setting the radGrid's EnableAJAX="True"?

  • Sebastian Sebastian admin's avatar

    Posted on Sep 20, 2007 (permalink)

    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

  • slai avatar

    Posted on Sep 20, 2007 (permalink)

    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!

  • slai avatar

    Posted on Sep 20, 2007 (permalink)

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

    Thanks.

  • Rycho Intermediate avatar

    Posted on Sep 21, 2007 (permalink)

    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

  • Sebastian Sebastian admin's avatar

    Posted on Sep 24, 2007 (permalink)

    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
    Attached files

  • Steve Steve admin's avatar

    Posted on Oct 23, 2007 (permalink)

    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

  • Steve Steve admin's avatar

    Posted on Jan 15, 2008 (permalink)

    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

  • Daniel Daniel admin's avatar

    Posted on Jul 27, 2009 (permalink)

    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

Skip Navigation LinksHome / Community & Support / Code Library / ASP.NET and ASP.NET AJAX > General and Integration Projects > Export RadGrid content to Excel/Word/CSV/PDF with Ajax enabled