I have a button inside RadAjaxPanel and i want to export it to the Excel Sheet, Below is the code i had written to do this task. If i removed the RadAjaxpanel then i can export the datatable into excel sheet. But when trying to export it to Excel using radajax panel, I'm getting this error: Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed."
<telerik:RadAjaxPanel ID="mainPanel" runat="server" LoadingPanelID="RadAjaxLoadingPanel"> <table class="reportSearch"> <tr> <td> <telerik:RadButton ID="btnExcelDetail" runat="server" Text="Excel" OnClick="btnExcelDetail_Click" ValidationGroup="SearchValidation" ClientEvents-OnRequestStart="requestStart"> <Icon PrimaryIconUrl="~/App_Themes/RnDThemes/images/insert_table_on.gif" PrimaryIconHeight="15" /> </telerik:RadButton> </td> <td> </table></telerik:RadAjaxPanel><script type="text/javascript">function requestStart(sender, args) { if (args.get_eventTarget().indexOf("btnExcelDetail") >= 0) args.set_enableAjax(false); }</script>public void ExporttoExcel(DataTable table, string filename) { try { HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ClearContent(); HttpContext.Current.Response.ClearHeaders(); HttpContext.Current.Response.Buffer = true; HttpContext.Current.Response.ContentType = "application/ms-excel"; HttpContext.Current.Response.Write(@"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">"); HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + filename + ""); HttpContext.Current.Response.Charset = "utf-8"; HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1250"); HttpContext.Current.Response.Write("<TABLE border='1' bgColor='#ffffff' " + "borderColor='#000000' cellSpacing='0' cellPadding='0' " + "style='font-size:10.0pt;background:white;'><TR>"); int columnscount = table.Columns.Count; for (int j = 0; j < columnscount; j++) { HttpContext.Current.Response.Write(@"<TD><B>" + table.Columns[j].ToString() + "</B></TD>"); } HttpContext.Current.Response.Write("</TR>"); foreach (DataRow row in table.Rows) { HttpContext.Current.Response.Write("<TR>"); for (int i = 0; i < table.Columns.Count; i++) { if (row[i].ToString().Trim().Length > 1 && row[i].ToString().Trim().StartsWith("0") && row[i].GetType().Name=="String") HttpContext.Current.Response.Write("<TD style=\"mso-number-format:\\@\">"); else HttpContext.Current.Response.Write("<TD>"); HttpContext.Current.Response.Write(row[i].ToString()); HttpContext.Current.Response.Write("</TD>"); } HttpContext.Current.Response.Write("</TR>"); } HttpContext.Current.Response.Write("</TABLE>"); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.SuppressContent = true; HttpContext.Current.ApplicationInstance.CompleteRequest(); } catch (Exception) { }