1

I have a dropdown called company and a button called export to excel and a gridview, also I have an update panel for both controls but when I export to excel dropdown won't work anymore, even if a want to export 2times I cannot without refreshing the page.

My export code:

   protected void Button1_Click(object sender, EventArgs e)
   {

      // HttpContext.Current.Response.Clear();
       HttpContext.Current.Response.AddHeader(
           "content-disposition", string.Format("attachment; filename={0}", "Kontratat-" + DateTime.Now.ToShortDateString() + ".xls"));
       HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";


       StringWriter sw = new StringWriter();
       HtmlTextWriter hw = new HtmlTextWriter(sw);


       HtmlForm frm = new HtmlForm();
       hw.WriteLine("<center><b><u><font size='5'>Kontratat</font></u></b></center>");//will be displayed in excel as a heading.
       GridView1.Parent.Controls.Add(frm);
       frm.Controls.Add(GridView1);
       frm.RenderControl(hw);
       HttpContext.Current.Response.Write(sw.ToString());
       HttpContext.Current.Response.Flush();
       HttpContext.Current.Response.End();

   }            

and my aspx code

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
    <asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
   <asp:PostBackTrigger ControlID="Button1" />
</Triggers>
<ContentTemplate>
    <asp:GridView ID="GridView1" runat="server" BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="4" CellSpacing="2" ForeColor="Black">
    </asp:GridView>
</ContentTemplate>

help me please

2 Answers 2

3

Because you have called the Response.End(), which ends the page execution, the body onload event would never be fired. The problem is sharepoint catches form submits and downloads so you cannot double click a button.

I had same issue, adding below script on aspx page helped me to resolve it

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

You can find reference here:

https://shenhengbin.wordpress.com/2012/03/16/cant-post-back-anything-after-file-download-in-sharepoint/

Refreshing page or making it to respond after downloading the file. All happening in Webpart

0
2

It is SharePoint which displays your value as a DropDown/Select. The Field value in the SQL database is stored as a String (with only the selected value).

When you export to Excel it exports values, not SharePoint functionality

1
  • thanks now I am clear I appreciate your help so much @danny Jul 11, 2016 at 7:52

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.