Response.End Terminating Page Events in SharePoint page

I have a button that evantually will generate a report in .csv format. So, a typical way is by using Response.End after writing in the context. Works well, user click the button, open/save box pop up, report generated as expected. However, after the box is close, attempting to click the button again to generate the report does not work. The button just don’t fire any event anymore. Found a similar problem posted in So, this issue is specifically related to pages hosted within SharePoint.

I found my solution after reading a related topic post by Marten about Ajax second postback not working in Sharepoint in UpdatePanel.

Windows SharePoint Services JavaScript has a “form onSubmit wrapper” which is used to override the default form action.  This work is put in place to ensure that certain types of URLs, which may contain double byte characters, will fully work across most postback and asynchronous callback scenarios.  However, if your scenarios do not involve double byte character URLs, you may successful disable this workaround and gain the ability to use ASP.NET AJAX UpdatePanels.

That script is actually preventing the form from being submit more than once if the user clicks before the Postback is completed. But it is the reason my button that call the Response.End not working after the first click. So, the solution to my problem is to add in a pieace of script to disable that SharePoint javascript that override the default form actions.

<script type="text/javascript">
_spOriginalFormAction = document.forms[0].action;