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

Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed

3 Answers 1708 Views
AjaxPanel
This is a migrated thread and some comments may be shown as answers.
Ashbin
Top achievements
Rank 1
Ashbin asked on 08 Jul 2016, 09:26 AM

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) { }

3 Answers, 1 is accepted

Sort by
0
Accepted
Viktor Tachev
Telerik team
answered on 11 Jul 2016, 01:18 PM
Hi,

If you are using the built-in export functionality for our controls it should work out of the box. Please ensure that you are using the latest version of the controls. The current release is 2016.2.607.

Check out the following example that illustrates how you can export RadGrid to excel.


In case you need to print the contents you can use the print feature:



Regards,
Viktor Tachev
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Al
Top achievements
Rank 1
Iron
Iron
Iron
answered on 25 Nov 2016, 03:15 PM

Hi Viktor,

Your answer refers to exporting a RadGrid to excel which is nice and easy but the OP is using an html table.

I face the same error trying to use response.write to output a table to excel as above - is there something I can do to make this work?

0
Viktor Tachev
Telerik team
answered on 30 Nov 2016, 12:10 PM
Hello,

If you would like to specify the structure of the Excel file manually you can use the Export Infrastructure. Check out the following article that describes the functionality.


When exporting the RadGrid you should use the InfrastructureExporting event and customize the Excel file.



Regards,
Viktor Tachev
Telerik by Progress
Telerik UI for ASP.NET AJAX is ready for Visual Studio 2017 RC! Learn more.
Tags
AjaxPanel
Asked by
Ashbin
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Al
Top achievements
Rank 1
Iron
Iron
Iron
Share this question
or