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

[Solved] ExportTo(Excel|PDF|*) & RadAjaxManager

4 Answers 173 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Christophe
Top achievements
Rank 1
Christophe asked on 05 Apr 2013, 05:05 AM
Hi,

What I'm trying to achieve sound pretty simple considering the features offered by ASP.NET AJAX.
I have an aspx page with a RadAjaxManager. This manager "ajaxifies" the loading of usercontrols within that page.
I'm loading a usercontrol embedding a RadGrid and everything works like a charm (as expected). Then I'm trying to export the grid to an Excel spreadsheet and nothing happens.
I tried many different options as described on this page  but it still doesn't work.

Here's a sample of my Default.aspx page with the RadAjaxManager
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest" >
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadRibbonBarAdminTools">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="PContent" LoadingPanelID="RadAjaxLoadingContextPanel">
                </telerik:AjaxUpdatedControl>
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingContextPanel" runat="server">
</telerik:RadAjaxLoadingPanel>
<asp:Panel ID="PContent" runat="server">
</asp:Panel>

Here's the code behind:

protected void Page_Load(object sender, EventArgs e)
{
        if (LatestLoadedControlName != null)
        {
            LoadUserControl(LatestLoadedControlName);
        }
}
 
protected void RadRibbonBar_ButtonClick(object sender, RibbonBarButtonClickEventArgs e)
{
        switch (e.Button.Text)
        {
            case "Summarized":
                LoadUserControl("usercontrols/data-Summaries.ascx");
                break;
            default:
                if (LatestLoadedControlName != null)
                {
                    Control previousControl = PContent.FindControl(LatestLoadedControlName.Replace("usercontrols/", "").Split('.')[0]);
                    if (!Object.Equals(previousControl, null))
                    {
                        this.PContent.Controls.Remove(previousControl);
                    }
                }
                break;
        }
}
 
public void LoadUserControl(string controlName)
{
    if (LatestLoadedControlName != null)
    {
        Control previousControl = PContent.FindControl(LatestLoadedControlName.Replace("usercontrols/", "").Split('.')[0]);
        if (!Object.Equals(previousControl, null))
        {
            this.PContent.Controls.Remove(previousControl);
            previousControl.Dispose();
        }
    }
    string userControlID = controlName.Replace("usercontrols/", "").Split('.')[0];
    Control targetControl = PContent.FindControl(userControlID);
    if (Object.Equals(targetControl, null))
    {
        UserControl userControl = (UserControl)this.LoadControl(controlName);
        userControl.ID = userControlID.Replace("/", "").Replace("~", "");
        this.PContent.Controls.Add(userControl);
        LatestLoadedControlName = controlName;
    }
}
 
protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
{
 
}

I have a ribbon bar on top of my page to load the different usercontrols.

Here is my data-summaries.ascx:
<telerik:RadGrid ID="rgIGTSummaryGrid" runat="server" DataSourceID="dsIGTDataSummary"
    AllowSorting="true" AllowPaging="true" PageSize="20" AutoGenerateColumns="false">
    <PagerStyle Visible="false" />
    <MasterTableView TableLayout="Auto" CommandItemDisplay="Top">
        <CommandItemSettings ShowExportToExcelButton="true" ShowAddNewRecordButton="false"
            ShowRefreshButton="false" />
        <Columns>
            <telerik:GridBoundColumn DataField="Username" HeaderText="Participant ID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Time" HeaderText="Date">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Sex" HeaderText="Gender">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Age" HeaderText="Age">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="YoE" HeaderText="Education">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Start" HeaderText="Start">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Gain" HeaderText="Overall Gain">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Currency" HeaderText="Currency">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="NbDeck" HeaderText="#Deck">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="DeckOrder" HeaderText="Deck Display Order">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="A" HeaderText="#A Pick">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="B" HeaderText="#B Pick">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="C" HeaderText="#C Pick">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="D" HeaderText="#D Pick">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="DeckA_Output" HeaderText="Deck A Overall output">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="DeckB_Output" HeaderText="Deck B Overall output">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="DeckC_Output" HeaderText="Deck C Overall output">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="DeckD_Output" HeaderText="Deck D Overall output">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
    <ExportSettings HideStructureColumns="false" IgnorePaging="true" OpenInNewWindow="true">
        <Excel Format="Biff" />
    </ExportSettings>
    <ClientSettings>
        <Scrolling AllowScroll="true" UseStaticHeaders="true" />
    </ClientSettings>
</telerik:RadGrid>
<telerik:RadAjaxLoadingPanel ID="ralpIGTSummaryGrid" runat="server">
</telerik:RadAjaxLoadingPanel>
<asp:SqlDataSource ID="dsIGTDataSummary" runat="server" ConnectionString="<%$ ConnectionStrings:NRPMonitorDB %>"
    SelectCommand="P_GetIGT_SummaryData" SelectCommandType="StoredProcedure">
    <SelectParameters>
        <asp:Parameter Name="sid" DefaultValue="1" />
    </SelectParameters>
</asp:SqlDataSource>

and there is nothing in the code behind as I don't need anything that is described in this WORKING example.

Don't know what to do now :(

4 Answers, 1 is accepted

Sort by
0
Christophe
Top achievements
Rank 1
answered on 05 Apr 2013, 06:03 AM
I tried to do this in my uc but no luck :

protected void rgIGTSummaryGrid_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridCommandItem)
    {
        Button btncmd = (e.Item as GridCommandItem).FindControl("btnExportToExcel") as Button;
        RadScriptManager.GetCurrent(this.Page).RegisterPostBackControl(btncmd);
    }
}
0
Jayesh Goyani
Top achievements
Rank 2
answered on 05 Apr 2013, 08:19 AM
Hello,

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


<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" ClientEvents-OnRequestStart="requestStart">
    </telerik:RadAjaxManager>


Thanks,
Jayesh Goyani
0
Christophe
Top achievements
Rank 1
answered on 08 Apr 2013, 02:41 AM
Thanks Jayesh, I tried this already but it looks like the js handler from the AjaxManager ClientEvents-OnRequestStart="requestStart" is never called when I click on any command from the grid. Placing a button within the <CommandItemTemplate> doesn't work any better.

The only way I can get this to work is to place a button OUTSIDE of the grid and then, this js handler gets invoked and then it works. But this is not the way I want this since there already are built-in command.

I must be doing something wrong somewhere but I can't get my mind around this issue. May be someone from Telerik would have a clue. Is this some "bug" ?

This works :
<telerik:RadButton ID="rbExportToExcel" Width="150px" Text="Export To Excel" OnClick="btnExcel_Click"
     runat="server" />
 <telerik:RadGrid ID="rgIGTSummaryGrid" runat="server" DataSourceID="dsIGTDataSummary"
     AllowSorting="true" AllowPaging="true" PageSize="20" AutoGenerateColumns="false"
     OnItemCreated="rgIGTSummaryGrid_ItemCreated">
     <PagerStyle Visible="false" />
     <MasterTableView TableLayout="Auto" CommandItemDisplay="Top">
         <Columns>
             <telerik:GridBoundColumn DataField="Username" HeaderText="Participant ID">
             </telerik:GridBoundColumn>
             <telerik:GridBoundColumn DataField="Time" HeaderText="Date">
             </telerik:GridBoundColumn>
             <telerik:GridBoundColumn DataField="Sex" HeaderText="Gender">
             </telerik:GridBoundColumn>
             <telerik:GridBoundColumn DataField="Age" HeaderText="Age">
             </telerik:GridBoundColumn>
             <telerik:GridBoundColumn DataField="YoE" HeaderText="Education">
             </telerik:GridBoundColumn>
             <telerik:GridBoundColumn DataField="Start" HeaderText="Start">
             </telerik:GridBoundColumn>
             <telerik:GridBoundColumn DataField="Gain" HeaderText="Overall Gain">
             </telerik:GridBoundColumn>
             <telerik:GridBoundColumn DataField="Currency" HeaderText="Currency">
             </telerik:GridBoundColumn>
             <telerik:GridBoundColumn DataField="NbDeck" HeaderText="#Deck">
             </telerik:GridBoundColumn>
             <telerik:GridBoundColumn DataField="DeckOrder" HeaderText="Deck Display Order">
             </telerik:GridBoundColumn>
             <telerik:GridBoundColumn DataField="A" HeaderText="#A Pick">
             </telerik:GridBoundColumn>
             <telerik:GridBoundColumn DataField="B" HeaderText="#B Pick">
             </telerik:GridBoundColumn>
             <telerik:GridBoundColumn DataField="C" HeaderText="#C Pick">
             </telerik:GridBoundColumn>
             <telerik:GridBoundColumn DataField="D" HeaderText="#D Pick">
             </telerik:GridBoundColumn>
             <telerik:GridBoundColumn DataField="DeckA_Output" HeaderText="Deck A Overall output">
             </telerik:GridBoundColumn>
             <telerik:GridBoundColumn DataField="DeckB_Output" HeaderText="Deck B Overall output">
             </telerik:GridBoundColumn>
             <telerik:GridBoundColumn DataField="DeckC_Output" HeaderText="Deck C Overall output">
             </telerik:GridBoundColumn>
             <telerik:GridBoundColumn DataField="DeckD_Output" HeaderText="Deck D Overall output">
             </telerik:GridBoundColumn>
         </Columns>
     </MasterTableView>
     <ExportSettings HideStructureColumns="false" IgnorePaging="true" OpenInNewWindow="true">
         <Excel Format="Biff" />
     </ExportSettings>
     <ClientSettings>
         <Scrolling AllowScroll="true" UseStaticHeaders="true" />
     </ClientSettings>
 </telerik:RadGrid>


But this doesn't:
<telerik:RadGrid ID="rgIGTSummaryGrid" runat="server" DataSourceID="dsIGTDataSummary"
    AllowSorting="true" AllowPaging="true" PageSize="20" AutoGenerateColumns="false"
    OnItemCreated="rgIGTSummaryGrid_ItemCreated">
    <PagerStyle Visible="false" />
    <MasterTableView TableLayout="Auto" CommandItemDisplay="Top">
        <CommandItemTemplate>
         <telerik:RadButton ID="rbExportToExcel" runat="server" Width="150px" Text="Export To Excel" OnClick="btnExcel_Click" />
        </CommandItemTemplate>
        <CommandItemSettings ShowExportToExcelButton="false" ShowAddNewRecordButton="false"
            ShowRefreshButton="false" />
        <Columns>
            <telerik:GridBoundColumn DataField="Username" HeaderText="Participant ID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Time" HeaderText="Date">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Sex" HeaderText="Gender">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Age" HeaderText="Age">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="YoE" HeaderText="Education">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Start" HeaderText="Start">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Gain" HeaderText="Overall Gain">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Currency" HeaderText="Currency">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="NbDeck" HeaderText="#Deck">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="DeckOrder" HeaderText="Deck Display Order">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="A" HeaderText="#A Pick">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="B" HeaderText="#B Pick">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="C" HeaderText="#C Pick">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="D" HeaderText="#D Pick">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="DeckA_Output" HeaderText="Deck A Overall output">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="DeckB_Output" HeaderText="Deck B Overall output">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="DeckC_Output" HeaderText="Deck C Overall output">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="DeckD_Output" HeaderText="Deck D Overall output">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
    <ExportSettings HideStructureColumns="false" IgnorePaging="true" OpenInNewWindow="true">
        <Excel Format="Biff" />
    </ExportSettings>
    <ClientSettings>
        <Scrolling AllowScroll="true" UseStaticHeaders="true" />
    </ClientSettings>
</telerik:RadGrid>


And my AjaxManager remains the same in both cases (PContent) being the asp panel where I load my usercontrols.
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest"
    ClientEvents-OnRequestStart="requestsStart">
        <telerik:AjaxSetting AjaxControlID="rbExportToExcel">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="PContent">
                </telerik:AjaxUpdatedControl>
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>


When "rbExportToExcel" is defined within the grid command header, it looks like my Ajax Manager can't find it but it is being registered properly.
0
Daniel
Telerik team
answered on 10 Apr 2013, 07:53 AM
Hello Chris,

I have to say I'm a bit confused by all this code showing different setups. I noticed that in one of the cases you are specifically ajaxifying the export button. This is something you shouldn't do because the export won't work with ajax. That said, it seems to me that the correct ajax settings are shown in the first post.
Well, I'd like to give you straight-to-the-point solution but for this purpose I need to see your whole setup including the master page (if you have any). If possible, please open a support ticket and attach the files so that I can examine them on my end. I don't need any binary files, nor I need a runnable code.
Alternatively, if the code is not too much you can post it here (only the actual version, please) and I will have a look.

Best regards,
Daniel
the Telerik team
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 their blog feed now.
Tags
Grid
Asked by
Christophe
Top achievements
Rank 1
Answers by
Christophe
Top achievements
Rank 1
Jayesh Goyani
Top achievements
Rank 2
Daniel
Telerik team
Share this question
or