This project has moved. For the latest updates, please go here.

Sys.WebForms.PageManagerParserErrorException received when attempting to create xlsx file

Nov 22, 2010 at 5:09 PM
Edited Nov 22, 2010 at 5:14 PM

I have a .Net web app that is .aspx pages that load .ascx user controls.  The user controls have updatepanels on them, and I've a sneaking suspicion that's what's causing the problem but I'm just not sure.

I'm trying to have the page generate a .xlsx file on a button click; no errors are caught in the click method itself, but when that method is complete I get the following error:  Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed

Here's the pertinent button click method code:


                using (tapconn)
                    string filename = "TapAppReport" + DateTime.Now.ToString("yymmdd") + ".xlsx";
                    FileInfo newfile = new FileInfo(filename);
                    using (ExcelPackage pkg = new ExcelPackage(newfile))
                        var wksht = pkg.Workbook.Worksheets.Add("TapApplicationReport");
                        wksht.Cells[1, 1].Value = "Premise Number";
                        wksht.Cells[2, 1].Value = "Customer Number";

                        wksht.Cells["A1:B1"].Style.Font.Bold = true;
                        wksht.Cells["A1:B1"].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                        wksht.Cells["A1:B1"].Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
                        wksht.Cells["A1:B1"].Style.Border.Top.Style = ExcelBorderStyle.Thin;
                        wksht.Cells["A1:B1"].Style.Border.Left.Style = ExcelBorderStyle.Thin;
                        wksht.Cells["A1:B1"].Style.Border.Right.Style = ExcelBorderStyle.Thin;
                        wksht.Cells["A1:B1"].Style.Fill.PatternType = ExcelFillStyle.LightUp;

SqlCommand tapCmd = new SqlCommand(reportQuery, tapconn); SqlDataAdapter tapDA = new SqlDataAdapter(tapCmd); DataSet tapDS = new DataSet(); tapDA.Fill(tapDS); DataTable tapDT = tapDS.Tables[0]; int i = 2; foreach (DataRow drow in tapDT.Rows) { wksht.Cells[i, 1].Value = drow[0].ToString(); wksht.Cells[i, 2].Value = drow[1].ToString(); i++; } pkg.Save(); } Response.Clear(); Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader("content-disposition", "attachment; filename=" + filename); Response.Write(filename); Response.End(); }


The .ascx design-side code looks like this:



<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Index.ascx.cs" Inherits="Pipeline.TapApplication.Index" %>
<%@ Register Assembly="eWorld.UI, Version=, Culture=neutral, PublicKeyToken=24d65337282035f2" Namespace="eWorld.UI" TagPrefix="ew" %>

<asp:ScriptManager ID="smTap" runat="server" EnablePageMethods="false" EnablePartialRendering="true" EnableScriptGlobalization="true" EnableScriptLocalization="true" />
<asp:UpdatePanel ID="upTap" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
        <asp:Table ID="tblSearch" runat="server" BorderStyle="None" Font-Names="Verdana" Font-Size="10px" Width="100%" Visible="true">

                <asp:TableCell ColumnSpan="2" HorizontalAlign="Center">
                    <asp:Button ID="btnShowReport" runat="server" Text="Show report with my search details" OnClick="btnShowReport_Click" Font-Size="10px" Font-Names="Verdana" /> <br /><asp:Button ID="btnExcelReport" runat="server" Text="Download report to Excel with my search details" OnClick="btnExcelReport_Click" Font-Size="10px" Font-Names="Verdana" />
        <br />

        <asp:AsyncPostBackTrigger ControlID="btnShowReport" EventName="Click" />
        <asp:AsyncPostBackTrigger ControlID="gvTap" EventName="RowCommand" />
        <asp:AsyncPostBackTrigger ControlID="btnUpdateTap" EventName="Click" />


Nov 22, 2010 at 5:20 PM

As usual, spending the time typing it out gave me an idea.  I added the btnExcelReport control as a PostBackTrigger, and now it'll open the file without throwing a fit. 

I posted this so everyone else can learn from my fail (the trigger one, not the 'write it out and then answer your own question' one.)

Valkyrie :)