Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I m working on a asp.net which, which has 2 buttons to generate files.
on one button click i generate a file and give user a popup of save.
on other button click i generate file and save file on the local machine.
On each button click, i need to update the button click time in database and show last button click time on the screen using labels.
In each button click event, i have called UpdateTimeOnScreen() function
In
UpdateTimeOnScreen()
function, i fetch last time button click from databse and show that time using labels
On one button that saves files on machine, the time is getting properly updated on screen.
but on other button click, that gives user a popup of save, the time is not getting updated.
I saw using debug, the above
UpdateTimeOnScreen()
is called properly and in that function, time is also assigned to labels but after execution of the code

C#
// Clear the content of the response
                    Response.ClearContent();

                    // Add the file name and attachment, which will force the open/cancel/save dialog box to show, to the header
                    Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);

                    // Add the file size into the response header
                    Response.AddHeader("Content-Length", bufferDataArray.Length.ToString());

                    Response.ContentType = "text/plain";

                    // Write the file into the response (TransmitFile is for ASP.NET 2.0. In ASP.NET 1.1 you have to use WriteFile instead)
                    Response.BinaryWrite(bufferDataArray);
                    // End the response
                    Response.End();


the labeltext , gets text as '
[System.Threading.ThreadAbortException] = {Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.}
' and time in the label is not getting updated

How to solve this issue?
Posted
Comments
sandeep nagabhairava 25-Jul-12 6:56am    
clear the label before updating it...

1 solution

In place of Response.End you have to use HttpContext.Current.ApplicationInstance.CompleteRequest method to bypass the code execution to the Application_EndRequest event.

Look here for details: Microsoft Support: ThreadAbortException Occurs If You Use Response.End, Response.Redirect, or Server.Transfer[^]
 
Share this answer
 
Comments
Member 8081020 25-Jul-12 7:11am    
Hi, Sandeep.
Thanks for help. I have tried with HttpContext.Current.ApplicationInstance.CompleteRequest
but it didnt worked
Sandeep Mewara 25-Jul-12 14:58pm    
Did you went through the article? That should do the trick as per Microsoft too.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900