0

I have an UpdatePanel with the following Triggers:

<Triggers>
    <asp:AsyncPostBackTrigger ControlID="ddlNames" EventName="SelectedIndexChanged" />
    <asp:PostBackTrigger ControlID="btnPullReport"/> 
</Triggers>

When the SelectedIndexChanged event is triggered I can see my loading gif from the UpdateProgress but when I click the btnPullReport button I do not.

It must be of type PostBackTrigger or else I get error:

0x800a139e - JavaScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed.

The btnPullReport creates an Excel file and prompts the user to save it.

The last lines in the btnPullReport_Click are these:

Response.Clear();
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment;  filename=Report.xlsx");
package.SaveAs(Response.OutputStream);
Response.End();

The error happens at Response.End(); and it states: {Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.}

How can I make it so that it displays the UpdateProgress bar after clicking the button also?

sd_dracula
  • 3,796
  • 28
  • 87
  • 158

2 Answers2

0

First, UpdateProgress shows only on asynchronous postbacks, your button is a "PostBackTrigger" and not an "AsyncPostBackTrigger". You must know also that UpdateProgress will not show if the response is received quickly, see the DisplayAfter property http://msdn.microsoft.com/en-us/library/vstudio/system.web.ui.updateprogress.displayafter(v=vs.100).aspx

Second, on partial updates the server side code must not use the Page.Response object, because this alter the response format. See this for more info http://forums.asp.net/p/1083296/1607033.aspx

DadyFuji
  • 243
  • 1
  • 12
  • I see. So it is impossible to display the loading bar in my case. It must be set as a PostBackTrigger only in order to work. – sd_dracula May 07 '14 at 14:22
  • Why did you define btnPullReport as trigger for the UpdatePanel ? Did it modify the content of the UpdatePanel ? If yes, you are perforce wrong, cause when you call response.clear() the browser will not receive those modifications. Can you give us the entire btnPullReport_Click code. – DadyFuji May 07 '14 at 14:26
  • If I don't call it as a trigger it crashes on the error above. If I do it actually works just fine and creates the file. It just doesn't show the UpdateProgress. – sd_dracula May 07 '14 at 14:28
  • Is the btnPullReport inside your UpdatePanel ? – DadyFuji May 07 '14 at 14:33
  • Yes. It is inside a table which is inside the panel. – sd_dracula May 07 '14 at 14:34
  • You have like a dilemmas: if you set the button as AsyncPostBackTrigger the UpdateProgress will not show, and if you set it the Response.Clear will cause the error, please see the solution I suggest you on my next answer. – DadyFuji May 07 '14 at 14:36
  • So the reason it there is because I also have some listboxes which need to share data but the Click method of the button which only work if the button is also in the update panel. – sd_dracula May 07 '14 at 14:37
0

After our discussion, I suggest you this: - On your UpdatePanel set the ChildrenAsTriggers Attribute to False. - Dont define the button as a trigger for the UpdatePanel (nor Sync or Async) - Use a manuel mechanism to show an UpdateProgress when the button is clicked. Like this one How can I create a "Please Wait, Loading..." animation using jQuery?

Community
  • 1
  • 1
DadyFuji
  • 243
  • 1
  • 12