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

Grid Export to Excel RadScriptManager

2 Answers 61 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Philip Senechal
Top achievements
Rank 1
Philip Senechal asked on 12 Oct 2010, 09:50 PM
I have an ajaxified grid that sits in a content page. The master page has a RadScriptManager tag and the content page has a ScriptManagerProxy tag. In the grid, I'm using the CommandItemSettings tag to display my Export to Excel buttons...

<CommandItemSettings ShowAddNewRecordButton="true" AddNewRecordImageUrl="../../App_Themes/InfoSource/Images/ico_add_24.png"
    AddNewRecordText="Add a Request" ShowExportToExcelButton="true" ExportToExcelImageUrl="../../App_Themes/InfoSource/Images/ico_excel_24.png"
    ExportToExcelText="Export to Excel" ShowExportToPdfButton="true" ExportToPdfImageUrl="../../App_Themes/InfoSource/Images/ico_acrobat_24.png"
    ExportToPdfText="Export to PDF" ShowRefreshButton="true" RefreshImageUrl="../../App_Themes/InfoSource/Images/ico_refresh_24.png"
    RefreshText="Refresh" />

I understand that I need to turn Ajax off for these buttons so that the export actually works. I'm trying to turn them off from the code behind using the following code...

if (e.Item is GridCommandItem)
{
    ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
 
    Button btncmd = (e.Item as GridCommandItem).FindControl("ExportToExcelButton") as Button;
    scriptManager.RegisterPostBackControl(btncmd);
    btncmd = (e.Item as GridCommandItem).FindControl("ExportToPdfButton") as Button;
    scriptManager.RegisterPostBackControl(btncmd);
}

but I get an error:

Value cannot be null.
Parameter name: control

 
scriptManager.RegisterPostBackControl(btncmd);

I can't seem to figure out if I just don't have the name of the button's correct or if I have the ScriptManager setup wrong. Can you give me a hand with this? Thanks.

2 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 13 Oct 2010, 03:01 PM
Hello Philip,

I do not recommend that you use the RegisterPostBackControl method for that purpose. Depending on your AJAX control, I suggest that you take advantage of one of the following ways:

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

<telerik:RadAjaxManager ClientEvents-OnRequestStart="onRequestStart" ...>

2) ASP.NET UpdatePanel (this will also work for Telerik AJAX controls)
Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(initializeRequestHandler);
function initializeRequestHandler(sender, args)
{
    if (args.get_postBackElement().id.indexOf("ExportTo") != -1)
    {
        args.set_cancel(true);
        sender._form["__EVENTTARGET"].value = args.get_postBackElement().id.replace(/\_/g, "$");
        sender._form["__EVENTARGUMENT"].value = "";
        sender._form.submit();
        return;
    }
}

In both snippets, I assume that the export is initiated from the built-in export buttons whose IDs are:
 ExportToExcelButton
 ExportToWordButton
 ExportToPdfButton
 ExportToCsvButton


For more information, please examine the following links:
Export from ajaxified grid
Export RadGrid content to Excel/Word/CSV/PDF with Ajax enabled

Best regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Philip Senechal
Top achievements
Rank 1
answered on 13 Oct 2010, 08:04 PM
Option 1 worked perfectly. I added the script and the additional parameter on the RadAjaxManager tag to all my master pages and everything works perfectly now. Thanks for the help!
Tags
Grid
Asked by
Philip Senechal
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Philip Senechal
Top achievements
Rank 1
Share this question
or