0

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.

I am getting this error when i am trying to create PDF of the page HTML using iTextSharp.

Any one has any idea how to resolve it?

This is my button click event in which i create PDF.

 protected void Button1_Click(object sender, EventArgs e)
        {
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=Filename.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            //Render PlaceHolder to temporary stream
            StringWriter stringWrite = new StringWriter();
            HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
            PlaceholderPdf.RenderControl(htmlWrite);
            StringReader reader = new StringReader(stringWrite.ToString());
            //Create PDF document
            Document doc = new Document(PageSize.A4);
            HTMLWorker parser = new HTMLWorker(doc);
            PdfWriter.GetInstance(doc, Response.OutputStream);
            doc.Open();

            try
            {
                //Create a footer that will display page number
                //Parse Html
                parser.Parse(reader);

            }
            finally
            {
                doc.Close();
            }
        }

Thanks in advance

Anirudh Agarwal
  • 655
  • 2
  • 7
  • 29
  • refer to this link http://forums.asp.net/t/1392827.aspx –  Nov 14 '13 at 07:01
  • It would be helpful if you posted some code... what controls do you have on the page? UpdatePanels? AjaxControlToolkit? –  Nov 14 '13 at 07:02
  • My page content which i m converting in PDF does not have any update panel. The content is parsed successfully but at the end it breaks don't know where? – Anirudh Agarwal Nov 14 '13 at 08:19
  • you might be missing catch function...there it may be showing u an actual error –  Nov 14 '13 at 08:25
  • Ni i do have a catch block.. n error is no thrown here. the eror is thrown on the java script. of some other page – Anirudh Agarwal Nov 14 '13 at 08:34
  • are you using same code as given in http://stackoverflow.com/questions/19947721/get-the-whole-page-as-a-pdf/19948099#19948099 or some sort of addition is done in it??pls show the addition part....did u have tried doing debug?? –  Nov 14 '13 at 08:38
  • Yes i am using the same code. That was my question only. When I have implemented that in a sample application then its working fine but when i included it in my main project it is throwing this error and rather the HTML is not having the style and css of that page – Anirudh Agarwal Nov 14 '13 at 10:00
  • if no difference than how could it is possible??....u were asking about image.jpg to have in pdf..did u have tried that?...have a look on namespace present in .cs page may be some is missing there also –  Nov 14 '13 at 11:59
  • You might be using response.write, server.transfer or similar within updatepanel; avoid that. Refer to [this article](http://weblogs.asp.net/leftslipper/archive/2007/02/26/sys-webforms-pagerequestmanagerparsererrorexception-what-it-is-and-how-to-avoid-it.aspx). –  Nov 14 '13 at 07:03
  • Have you tried adding a `Response.Clear()` at the top of the `Button1_Click()` code? – Chris Haas Nov 14 '13 at 22:35

0 Answers0