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

[Solved] ExportToExcel and AJAX

3 Answers 234 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 2
Michael asked on 20 Feb 2008, 02:46 PM
I'm trying to get my link button to work with the RadGrid in generating an Excel file.  I have a RadAjaxManager which is performing some AJAX on my page - most notably the link button and grid.  However, when clicking the link button nothing happens and after doing some research I think I understand why...

The export functionality cannot use AJAX, therefore it needs to be disabled when making the request.  I found a thread in the forums that posted some sample code and it looks great.  The only difference (and the one I believe is causing the issue) is that the example is done on a single content page, whereas mine is inheriting a Master Page.  So anyway, the client-side code of interest looks like this...

 <script type="text/javascript">

    function mngRequestStarted(ajaxManager, eventArgs)

    {

      if(eventArgs.EventTarget == "lnkExcel")

      {

         eventArgs.EnableAjax = false;

      }

    }

 </script>


This does not have any affect when used within the Master Page.  I can actually see a slight movement of the grid so I know Ajax is still working here.  After a bit of debugging, I found the if statement never returns true because the control is nested in the Master Page and gets a funky id (thanks ASP.NET).  


How do I change the "lnkExcel" part to return the id of the control even when it's on a Master Page?


Thanks.

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 20 Feb 2008, 03:07 PM
Hello Michael,

Here is an example how to achieve this:

 <script type="text/javascript">
    function mngRequestStarted(ajaxManager, eventArgs)
    {
      if(eventArgs.EventTarget.indexOf("lnkExcel") != -1)
      {
         eventArgs.EnableAjax = false;
      }
    }
 </script>

Best wishes,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Michael
Top achievements
Rank 2
answered on 20 Feb 2008, 06:06 PM
Hi Vlad,

Although that did stop the Ajax, I'm still having a heck of a time trying to get the export to work.  The following code doesn't trigger the link button click event.  When I take out the link button from the manager the event fires but no excel dialog.  Please help.
 <script type="text/javascript"
 function mngRequestStarted(ajaxManager, eventArgs) 
    { 
      if(eventArgs.EventTarget.indexOf("lnkExcel") != -1) 
      { 
         eventArgs.EnableAjax = false
      } 
    } 
 </script> 
<telerik:RadScriptManager ID="scriptmanager" runat="server" /> 
 
<telerik:RadAjaxManager ID="RadAjaxManager1"  ClientEvents-OnRequestStart="mngRequestStarted" runat="server" DefaultLoadingPanelID="loadingpanel"
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="btnSubmit"
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="lnkExcel" /> 
                    <telerik:AjaxUpdatedControl ControlID="rdgrdServiceDetails" LoadingPanelID="loadingpanel" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
           <telerik:AjaxSetting AjaxControlID="lnkExcel"
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="rdgrdServiceDetails" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
            <telerik:AjaxSetting AjaxControlID="rdgrdServiceDetails"
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="rdgrdServiceDetails" LoadingPanelID="loadingpanel" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    <ClientEvents OnRequestStart="mngRequestStarted" /> 
    </telerik:RadAjaxManager> 

    Protected Sub rdgrdServiceDetails_DataBound(ByVal sender As ObjectByVal e As System.EventArgs) Handles rdgrdServiceDetails.DataBound 
        If rdgrdServiceDetails.MasterTableView.Items.Count > 0 Then 
            lnkExcel.Visible = True 
        Else 
            lnkExcel.Visible = False 
        End If 
    End Sub 
 
    Protected Sub lnkExcel_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles lnkExcel.Click 
        rdgrdServiceDetails.ExportSettings.ExportOnlyData = True 
        rdgrdServiceDetails.ExportSettings.IgnorePaging = True 
        rdgrdServiceDetails.ExportSettings.OpenInNewWindow = True 
        rdgrdServiceDetails.MasterTableView.ExportToExcel() 
    End Sub 


0
Steve
Telerik team
answered on 25 Feb 2008, 04:05 PM
Hello Michael,

Can you elaborate on your scenario. Is the RadGrid and RadAjaxManager both in the content page? Have you reviewed this code library and can you reproduce the issue in any of them when inheriting from MasterPage?

Greetings,
Steve
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Michael
Top achievements
Rank 2
Answers by
Vlad
Telerik team
Michael
Top achievements
Rank 2
Steve
Telerik team
Share this question
or