UpdateProgress, Server.execute and Sys.WebForms.PageRequestManagerParserErrorException

Last post 02-22-2008 5:52 PM by kirchi. 6 replies.

Sort Posts:

  • UpdateProgress, Server.execute and Sys.WebForms.PageRequestManagerParserErrorException

    02-21-2008, 5:50 PM

    Hi, I have an UpdateProgress control on Page A that shows a "Please wait..." message after the user clicks a button to run a report.  When the button is clicked I run a response.redirect to Page B that has the code for running the report.  The problem with that is the "Please wait..." message stays visible on Page A forever, even after the pdf report comes up in another window.  This happens because the code that runs the report is on Page B, and the code does not return to Page A where the UpdateProgress control is so it doesn't turn off. 

     I read somewhere that I could use server.execute instead of response.redirect which will execute the report code on Page B, then return the focus to Page A so that the "Please wait..." message will turn off.  I tried this and it would have worked perfectly if it weren't for the Sys.WebForms.PageRequestManagerParserErrorException error message.  When the code finishes on Page B and the focus is back to Page A, the "Please wait..." message does in fact disappear as it should, but the report does not come up in a pdf window because of the error message.  Does anyone have any ideas how I can get around this?  I read a long post about this error message, but none of the work-arounds seem to work for me.  Is it because I am using server.execute?  If so, is there some other way that I can redirect to Page B to run the report, but then somehow turn off the visibility of the UpdateProgress control when the code on Page B completes?  The UpdateProgress control is on Page A and I don't know how to turn off the visibility once the code in Page B completes.  Is there code I can use in Page B to turn off the visibility of a control in Page A?

    Thanks for any help you can provide!

  • Re: UpdateProgress, Server.execute and Sys.WebForms.PageRequestManagerParserErrorException

    02-21-2008, 10:20 PM

    Hi

    It is not a good practice to use Response.Write or server.execute from within an ASP.NET page in general. As UpdatePanels work by intercepting the page rendering process you are recieving the errors.

    You can put the code to generate the data in an HTTPHandler or you can make the button a PostBackTrigger.

    Because of the way updatepanels manage the DOM elements within them, you cannot use Response.Write() with them.

    http://weblogs.asp.net/leftslipper/archive/2007/02/26/sys-webforms-pagerequestmanagerparsererrorexception-what-it-is-and-how-to-avoid-it.aspx

    http://vijaymodi.wordpress.com/2007/04/13/syswebformspagerequestmanagerparsererrorexception/

    http://forums.asp.net/t/1038252.aspx

    Adding <pages enableEventValidation="false"/> to your web.config (inside system.web) usually works when setting ValidateRequest="false" does not.

    For more information about EnableEventValidation, see: http://msdn2.microsoft.com/en-us/library/system.web.ui.page.enableeventvalidation.aspx

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
  • Re: UpdateProgress, Server.execute and Sys.WebForms.PageRequestManagerParserErrorException

    02-22-2008, 2:57 PM

    Thanks for the response.  Since I can't use server.execute to accomplish this, can you give me an example of how to do it in an HTTPHandler?  I have never used that before.  Thanks!

  • Re: UpdateProgress, Server.execute and Sys.WebForms.PageRequestManagerParserErrorException

    02-22-2008, 4:49 PM
    • Contributor
      2,422 point Contributor
    • kirchi
    • Member since 03-07-2007, 2:47 AM
    • Posts 328

    Hi HeatherGebbia,

    I suppose the following scenario:

    1) place the  button, hidden iframe and hidden progress indicator (span for example) into the form:

    <asp:Button runat="server" ID="btn" OnClientClick="$get('ifr').src='var rnd=new Date();GetReport.aspx?rnd='+rnd;" />

    <iframe id="ifr" name="ifr" style="display:none"></iframe>

     

    Here GetReport.aspx is the "second" page, that generated the report:

    protected void Page_Load(object sender, EventArgs e)

    {

    Thread.Sleep(3000);

    Response.ClearHeaders();

    Response.ContentType =
    "application/octet-stream";

    Response.AddHeader("content-disposition", "attachment; filename=MVCToolkit.zip");

    Response.WriteFile(Server.MapPath("~/MVCToolkit.zip"));

    Response.End();

    }

    That's it

    Now you should change the content type to desired one (I suppose pdf in your case)

    BUT here you can not use Progress Indicator.

    If you need progress indicator do the following (in more simple words):

    1) Place a button in an UpdatePanel

    2) User Clicks on Button and Ajax Progress Indicator simply shows that there is some work performing behids the scene

    3) On the server generate report into temporary directory.

    4) On the server after report is ready register startup script using ScritManager.RegisterStartupScript method, the script will change the src property of an hidden iframe and point it to the generated file.

    5) on the browser user will see that progress interrupted - because asynchronous postback finished and returned, but immidiately executes javascript that pops up a save/open dialog.

     

    Hope this helps

     

     

    My blog: http://blog.devarchive.net
    My samples: http://devarchive.net
  • Re: UpdateProgress, Server.execute and Sys.WebForms.PageRequestManagerParserErrorException

    02-22-2008, 4:49 PM
    • Contributor
      2,422 point Contributor
    • kirchi
    • Member since 03-07-2007, 2:47 AM
    • Posts 328

    the previous post submitted twice, so I am clearing this ...

    My blog: http://blog.devarchive.net
    My samples: http://devarchive.net
  • Re: UpdateProgress, Server.execute and Sys.WebForms.PageRequestManagerParserErrorException

    02-22-2008, 5:29 PM

    Can you explain #4 above?  Do I use ScriptManager.RegisterStartupScript on the page where my code is running the report (GetReport.aspx)?  This code expects some arguments and since I've never used ScriptManager.RegisterStartupScript before, can you tell me what arguments need to go there?  Thanks so much for your help!

  • Re: UpdateProgress, Server.execute and Sys.WebForms.PageRequestManagerParserErrorException

    02-22-2008, 5:52 PM
    Answer
    • Contributor
      2,422 point Contributor
    • kirchi
    • Member since 03-07-2007, 2:47 AM
    • Posts 328

    Yes sure -

    you should not generate reports in GetReport.aspx if you use my 2-nd supposed scenario.

    Instead move your methods to first page (or some shared code - like App_Code), also you will need to modify it the way it writes reports to the temporary directory as files.

    in step 4 - after you generated the report just wrtite script using this method:

    string initScript = "var rnd=new Date();$get('ifr').src='"+myGeneratedFileName+"'+'?rnd='+rnd;";

    ScriptManager Smgr = ScriptManager.GetCurrent(Page);if (Smgr != null)

    {

    if (Smgr.IsInAsyncPostBack)

    {

    ScriptManager.RegisterStartupScript(this, this.GetType(), "FireDownloadScript", initScript, true);

    }

    }

    more important here is initScript variable - you will place there the javascript that will execute in browser right after client gets response.

    You can find more about this method here: http://msdn2.microsoft.com/en-us/library/system.web.ui.scriptmanager.registerstartupscript.aspx

     

    My blog: http://blog.devarchive.net
    My samples: http://devarchive.net
Page 1 of 1 (7 items)