Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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:

HttpContext.Current.Response.Clear();
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));
HttpContext.Current.Response.Write(strContents);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();

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
add comment

4 Answers

up vote 2 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; 
_spSuppressFormOnSubmitWrapper=true;";
share|improve this answer
add comment

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

http://mytechsoup.com/?p=36

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

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. –  thantos Sep 14 '12 at 15:05
add comment

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">
    _spOriginalFormAction=document.forms[0].action;
    _spSurppressFormOnSubmitWrapper = true;
</script>

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. –  thantos 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
add comment

Your Answer

 
discard

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.