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 french-industries.com. 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;
_spSuppressFormOnSubmitWrapper=true;
</script>

5 thoughts on “Response.End Terminating Page Events in SharePoint page”

  1. Thanks so much this works great. For those who can’t figure it out, an easy way is to just stick this script into a content editor web-part on the same page as your other web-part (place it above your custom web part in the webpart ordering).

    Also if you copy and paste the script above, retype the type=’text/javascript’ portion because it may copy the incorrect single quote characters. I replaced them with ” ” and it started working great!

Leave a Reply

Your email address will not be published. Required fields are marked *