Click here to Skip to main content
15,890,408 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi,

I have a set of asp controls in my web page as below
ASP.NET
<asp:DropDownList ID="ddlScope" runat="server" CssClass="combobox noMarginBottom marginRight10 floatLeft"></asp:DropDownList>
                            <asp:Button ID="btnApplyfilter" runat="server" Text="Apply Filter" OnClick="BtnApplyfilter_Click" CssClass="submitBtn floatLeft marginRight10 marginLeft10" />
                            <asp:Button ID="btnClearfilter" runat="server" Text="Clear Filter" OnClick="BtnClearfilter_Click" CssClass="submitBtn floatLeft marginRight10" />
                            <asp:Button ID="btnExport" runat="server" Text="Export" OnClick="BtnExport_Click" CssClass="submitBtn floatLeft marginRight10" />      


When i click each and every button there is a page submit. It all works fine until we click the export button. When we click the export button we are exporting some data to excel using the code below

C#
var response = Context.Response;
               response.Clear();
               response.ClearHeaders();
               response.ClearContent();
               response.AddHeader("Content-Disposition", string.Concat("attachment; filename=Data_", string.Format("{0:yyyyMMdd_hhmmsstt}", DateTime.Now), ".xlsx"));
               response.AddHeader("Content-Length", buffer.Length.ToString());
               response.ContentType = "application/vnd.ms-excel";
               response.Flush();
               response.BinaryWrite(buffer);
               response.End();


But after the file are exported the page just freezes. All buttons clicks wont work.

Can anyone please help me out.

Thanks
Arjun Menon
Posted
Comments
Herman<T>.Instance 8-Apr-15 7:47am    
You don't export XLSX this way. You create an XLS content with XLSX as filename.

1 solution

Add this method to your page:
C#
public override void VerifyRenderingInServerForm(Control control)
   {
       // Confirms that an HtmlForm control is rendered for the specified ASP.NET server control at run time.
   }
 
Share this answer
 
Comments
Arjun Menon U.K 8-Apr-15 7:53am    
Add this to my ascx.cs and then try debugging?
Herman<T>.Instance 8-Apr-15 7:59am    
I use it in ASPX.cs files
why not test it?
Arjun Menon U.K 8-Apr-15 8:38am    
ok... am new to the aspx concept. So one more doubt. What does this function do and do i have to wrtie anything there? Also do i have to call it explicitly in Page Load or something?
Arjun Menon U.K 8-Apr-15 8:41am    
"no suitable method found to override"
Got this when i build the solution
Herman<T>.Instance 8-Apr-15 9:29am    
Did you have a FORM tag in the ascx/aspx?
When I export to Excel I redirect to an empty ASPX page. Then the method works. You have to set your data in Session before redirecting. After redirecting set the object and clear them from session

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900