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("yyyy.MM.dd.HH.mm.ss") + ".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 ?

4 Answers 4


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

btnExport.UseSubmitBehavior = false;
btnExport.OnClientClick = "_spFormOnSubmitCalled = false; 

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]

  • 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
    Commented Sep 13, 2012 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. Commented Sep 13, 2012 at 14:38
  • Thantos. Thanks for the reply.. just figured out the solution for this. You may check and comment. Thanks again.
    – Amin Sayed
    Commented Sep 14, 2012 at 12:46

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;";
  • Of course not having submit the form always helps. Good find. Commented Sep 14, 2012 at 15:05

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



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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