SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm having a Visual Webpart that allows user to select Managed Properties and find out what is stored inside it. The result is displayed inside a gridview which he/she can export it to excel.

It is same another export to excel code that I have written:

string filename = "Report_" + DateTime.Now.ToString("") + ".xls";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + filename);
HttpContext.Current.Response.ContentType = "application/ms-excel";
GridView tempGridView = new GridView();
tempGridView.AutoGenerateColumns = false;
string strContents = getGridViewHtml(GetExportingGridView(tempGridView));

But after the file is downloaded the page stops responding to any events.

I cannot have one more (dummy) page which can take this request and make a download operation and go off.

Any work around for this issue ?

share|improve this question
up vote 4 down vote accepted

I have put your code in the page load event and it resolves the issue.

btnExport.UseSubmitBehavior = false;
btnExport.OnClientClick = "_spFormOnSubmitCalled = false; 
share|improve this answer

I had the same issue on my last project. The main problem is sharepoint catches form submits and downloads so you cannot double click a button.

So I added this to the page

<script type="text/javascript">
    _spSurppressFormOnSubmitWrapper = true;

I Think that fixed that issue, but I ended up using the SharePoint download page:

/_layouts/download.aspx?sourceurl=[file url]&source=[current page]

share|improve this answer
Hi Thantos, thanks for the quick reply. So do you mean that merely pasting that script will not work ? I need to use the download.aspx page as well ? If yes then, I didn't understand what do you mean by [file url] as my code is just exporting the gridview content to excelsheet. Also [current page] ? you mean the just "audit.aspx" or the entire URL ? thanks. – Amin Sayed Sep 13 '12 at 14:01
Just try the code, if you are just exporting the data directly, the download page won't work for you, only if it was a sp library doc, so try the script. – Sam Sussman Sep 13 '12 at 14:38
Thantos. Thanks for the reply.. just figured out the solution for this. You may check and comment. Thanks again. – Amin Sayed Sep 14 '12 at 12:46

The following link was very helpful in understanding the response issue that I was facing. It was solved by setting a few flags.

share|improve this answer
Thanks.. this helps too... – Amin Sayed Apr 12 '13 at 9:25

Ok I just figured it out.

We are just making the export button not to act like a form submit button.

Below is the code for this.

  btnExport.UseSubmitBehavior = false;
  btnExport.OnClientClick = "_spFormOnSubmitCalled = false; _spSuppressFormOnSubmitWrapper=true;";
share|improve this answer
Of course not having submit the form always helps. Good find. – Sam Sussman Sep 14 '12 at 15:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.