locked
JavaScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException RRS feed

  • Question

  • User-73514677 posted

    HI.

    I am using VS 2010, C# and ASP.NET Web Application.

    I am trying to export dataset to excel. I am getting an error as - JavaScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed.

    The excel is not created. I have used the below code:

     DataSet ds = getDataSetExportToExcel(con);
                        using (XLWorkbook wb = new XLWorkbook())
                        {
                            wb.Worksheets.Add(ds);
    
                            Response.Clear();
                            Response.Buffer = true;
                            Response.Charset = "";
                            Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                            Response.AddHeader("content-disposition", "attachment;filename= " + filename1 + ".xlsx");
                            using (MemoryStream MyMemoryStream = new MemoryStream())
                            {
                                wb.SaveAs(MyMemoryStream);
                                MyMemoryStream.WriteTo(Response.OutputStream);
    
                                Response.Flush();
                                Response.End();
                            }
                        }
    

    The error is at line - Response.End()

    I have the scriptmanager added in the page with the below code:

      <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" AsyncPostBackTimeout="360000">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="upd1" runat="server">
            <ContentTemplate>

    How to fix this?

    Thanks

    Wednesday, June 19, 2019 4:22 AM

Answers

  • User-73514677 posted

    Hi.

    Thanks for the reply. I used the below line in page load and it is working:

     ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
     scriptManager.RegisterPostBackControl(this.btnExport);

    Thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 24, 2019 8:15 AM

All replies

  • User283571144 posted

    Hi venkatzeus,

    According to your description, I couldn't understand your quesiton clearly.

    Do you mean you call the webmethod in the code-behind through the page method and get the PageRequestManagerParserErrorException?

    Could you please post more details codes about your webmethod and details aspx page for us to reproduce the issue?

    If you could post more details information, it will be more easily for us to reproduce the issue and find out the solution.

    Best Regards,

    Brando

    Wednesday, June 19, 2019 6:37 AM
  • User-73514677 posted

    Hi.

    Thanks for the reply. I am trying to export dataset to Excel. In my aspx page, I have used script manager. I am using VS 2010, C# , ASP.NET Web application.

    The code gets the data from the dataset and passes to memory stream and when the line hits the response.end , I am getting this error

    Wednesday, June 19, 2019 6:45 AM
  • User283571144 posted

    Hi venkatzeus,

    Thank you for explaining your codes again.

    Could you please tell when you run the export excel codes? In a button click event or Scriptpagemanager pagemethod? 

    Is this button is inside the updatepanel? 

    Best Regards,

    Brando

    Thursday, June 20, 2019 1:39 AM
  • User-73514677 posted

    Thanks for the reply.

    Button click event calls the Export functionality and the button is inside the update panel

    Thursday, June 20, 2019 11:34 AM
  • User-943250815 posted

    Seems you posted just a piece of code and all code, with code provided i'm not sure if it works, it drive me think MemoryStream ast end will be empty.
    Anyway, supposing it works, you can make Scripts to run Before and After Async Postback, check thi link https://www.dotnetcurry.com/ShowArticle.aspx?ID=256
    There is also ScriptManager.AsyncPostBackError Event https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.scriptmanager.asyncpostbackerror?view=netframework-4.8

    With scripts in place, on your browser using F12 you can also set a breakpoint on endhandler to inspect values.

    If possible, refactor you code to have it inside a Try/Catch block, so you can grab exceptions before return data to browser

    Thursday, June 20, 2019 12:36 PM
  • User-73514677 posted

    Hi.

    Thanks for the reply. I used the below line in page load and it is working:

     ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
     scriptManager.RegisterPostBackControl(this.btnExport);

    Thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 24, 2019 8:15 AM