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

[Solved] RadAjaxPanel Export to Excel

1 Answer 138 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Durga
Top achievements
Rank 1
Durga asked on 22 Jun 2009, 09:46 PM
Hi,

I am facing the problem with RadAjaxPanel when exporting data into excel from RadGrid. "Object reference not set to an instance of object."

my code likes below:

<asp:Content ID="Content1" ContentPlaceHolderID="mainContent" runat="Server">
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
                <script type="text/javascript">
                function pnlRequestStarted(ajaxPanel, eventArgs)
                {
                  if(eventArgs.EventTarget == "<%=lnkRadGridLineItemExport.UniqueId %>")
                  {
                     eventArgs.EnableAjax = false;
                  }
                }
                </script>
            </telerik:RadCodeBlock>
<telerik:RadAjaxPanel ID="RadAjaxPanel1" EnableAJAX="true" LoadingPanelID="RadAjaxLoadingPanel1"
        runat="server" ClientEvents-OnRequestStart="pnlRequestStarted">
 <asp:LinkButton runat="server" ID="lnkRadGridLineItemExport" Text="Export To Excel"
                        OnClick="RadGridLineItemExportToExcel"></asp:LinkButton>
<telerik:RadGrid ID="RadGridLineItem" runat="server" AllowSorting="True" AllowPaging="True"
            PageSize="10" AutoGenerateColumns="False" Skin="Office2007" AllowAutomaticUpdates="True"
            AllowMultiRowSelection="False" Font-Size="Smaller" Style="width: 95%; height: 200px;
            margin: auto">
</telerik:RadGrid>
</telerik:RadAjaxPanel>
</asp:Content>

code behing file:
Protected Sub RadGridLineItemExportToExcel(ByVal sender As Object, ByVal e As System.EventArgs)
        RadGridLineItem.DataSource = ViewState("OrderHeader")
        RadGridLineItem.DataBind()      
        RadGridLineItem.MasterTableView.ExportToExcel()
    End Sub


Any help would be appreciated.

Thanks/Durga

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 23 Jun 2009, 07:25 AM
Hi Durga,

Here the entire RadAjaxPanel with the its child control is inside the Content page. I guess the issue is caused since you are trying to access the LinkButton on the client side using wrong ID. I got it working using the following code.

JS:
 
<script type="text/javascript" > 
 function pnlRequestStarted(ajaxPanel, eventArgs) 
 { 
  debugger
   if(eventArgs.EventTarget =="ctl00$mainContent$lnkRadGridLineItemExport"
     { 
                eventArgs.EnableAjax = false
     } 
 } 
 
</script> 

You may put a debugger inside the client side function and check for the exact ID for the LinkButton.

Thanks
Shinu
Tags
General Discussions
Asked by
Durga
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or