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

Export PDF/Excel No longer working when coverted to Asp.net Ajax

1 Answer 183 Views
Grid
This is a migrated thread and some comments may be shown as answers.
RJ
Top achievements
Rank 1
RJ asked on 01 Apr 2013, 10:26 AM
Hi All, My export no longer working when I converted my radcontrols to asp.net ajax. Previously I'm using Classic radcontrol Q32008 .Net 2.0 and when I converted to Q12013 .Net 4.5, all my exports does not work at all including problem with response.write.

Error on export using datatable/dataset:
0x800a139e - Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.

Heres my code:
Private Sub btnExportToExcel_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnExportToExcel.Click
       Dim dtS As New DataTable, dtR As New DataTable, dr As DataRow, dg As New DataGrid
       Dim Query As String = ViewState.Item("cSQL")
 
       dg.GridLines = GridLines.Both
       dg.ForeColor = Color.Black
       dg.AutoGenerateColumns = False
 
       dtR.Columns.Add("Type", Type.GetType("System.String"))
       dtR.Columns.Add("Status", Type.GetType("System.String"))
       dtR.Columns.Add("CLIENT", Type.GetType("System.String"))
       dtR.Columns.Add("LINE_ITEM_GROUP", Type.GetType("System.String"))
       dtR.Columns.Add("Receive_Date", Type.GetType("System.String"))
       dtR.Columns.Add("Sender", Type.GetType("System.String"))
       dtR.Columns.Add("AMOUNT", Type.GetType("System.Decimal"))
       dtR.Columns.Add("Comment", Type.GetType("System.String"))
 
 
       CreateColumn(dg, "Type", "Type", "")
       CreateColumn(dg, "Status", "Status", "")
       CreateColumn(dg, "CLIENT", "Client Name", "")
       CreateColumn(dg, "LINE_ITEM_GROUP", "Line Item Group", "")
       CreateColumn(dg, "RECEIVE_DATE", "Receive<br>Date", "")
       CreateColumn(dg, "Sender", "Sender", "")
       CreateColumn(dg, "AMOUNT", "Expense<br>Amount", "{0:###,###,##0;(###,###,##0); }")
       CreateColumn(dg, "Comment", "Comment", "")
 
 
       dtS =  ViewState.Item("drdr")
       Dim drR As DataRow
       For Each dr In dtS.Rows
           drR = dtR.NewRow
           drR("Type") = dr("Type")
           drR("Status") = dr("Status")
           drR("CLIENT") = dr("CLIENT")
           drR("LINE_ITEM_GROUP") = dr("LINE_ITEM_GROUP")
           drR("RECEIVE_DATE") = dr("RECEIVE_DATE")
           drR("SENDER") = dr("SENDER")
           drR("AMOUNT") = dr("AMOUNT")
           drR("Comment") = dr("Comment")
 
           dtR.Rows.Add(drR)
       Next
 
       Dim dv As New DataView(dtR)
       dv.Sort = "Client"
       dg.DataSource = dv
       dg.DataBind()
 
       Response.Clear()
       Response.ContentType = "application/vnd.ms-excel"
       Dim stringWrite As New System.IO.StringWriter
       Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
       dg.RenderControl(htmlWrite)
       Response.Write(stringWrite.ToString)
       Response.End()
   End Sub

Export To PDF/Excel using RadGrid--- > nothing happened

Private Sub btnExportToPDF_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnExportToPDF.Click
       Me.PDFGrid.ExportSettings.IgnorePaging = True
 
       Me.PDFGrid.DataSource = ViewState.Item("drdr")
       Me.PDFGrid.DataBind()
 
       
       Me.PDFGrid.MasterTableView.ExportToPdf()
   End Sub
 
Private Sub btExportToExcel_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btExportToExcel.Click
 
       Me.PDFGrid.ExportSettings.IgnorePaging = True
 
       Me.PDFGrid.DataSource = ViewState.Item("drdr")
       Me.PDFGrid.DataBind()
 
       Me.PDFGrid.MasterTableView.ExportToExcel()
 
   End Sub














1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 20 Aug 2013, 11:11 AM
Hi RJ,

The exporting feature works only with regular post backs. This means, that the asynchronous postback should be canceled when performing an export. Please have look at this documentation on Exporting.It clearly shows how to Export from ajaxified grid,Exclude controls from ajaxifying and Export RadGrid content to Excel/Word/CSV/PDF with Ajax enabled.

Thanks,
Princy
Tags
Grid
Asked by
RJ
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or