Click here to Skip to main content
15,884,995 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi everybody,

I get a problem when I try to export data to excel and send file to client.

C#
string data = hidden_data.Value;
data = HttpUtility.UrlDecode(data);
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=Data.xls");
Response.Charset = "UTF-8";
Response.ContentType = "application/excel";
HttpContext.Current.Response.Write(data);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();

_btnExport.Enabled = false;
radList.Enabled = false;
lblState.Text = "Done";


After transmitting excel file, I want _btnExport and radList to be disabled and lblState to display "Done". I receive excel file and open it normally, but _btnExport and radList are still enabled, lblState display nothing.

Many thanks.
Posted
Updated 20-Jan-15 21:07pm
v3
Comments
Tejas Vaishnav 21-Jan-15 1:09am    
And what type of error you got? can you please explain more..
Kaito Nguyen 21-Jan-15 1:33am    
I want _btnExport, radList to be disabled and lblState to display text "Done" after the excel file was transmitted, but nothing's happen (_btnExport and radList are still enabled and lblState display nothing).
Tejas Vaishnav 21-Jan-15 2:26am    
You mention in your question that, HttpContext.Current.Response.End() do not work? that means your exported excel file is not actually export to client.. is your excel file is going to exported to client, you can view that file?
And your button and radlist is not going to disabled as you mention in your comment.. that is totally different thing then your question.
Kaito Nguyen 21-Jan-15 2:36am    
No. In my question, I mention that "3 code line after (below) HttpContext.Current.Response.End()" do not work. I didn't mean HttpContext.Current.Response.End() do not work.
deepankarbhatnagar 21-Jan-15 2:43am    
please elaborate your question

1 solution

There is no life after Response.End() - https://msdn.microsoft.com/en-us/library/system.web.httpresponse.end.aspx[^]
In your case the only thing sent back to the client is the data containing the excel file...As for your button, it keeps its previous state...
 
Share this answer
 

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