Asp.Net : html to excel problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Am creating a HTML Report in asp.net. To save this report to excel on
client-side, i write this code:
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition", "attachment; filename=Report.xls")

But once the report is saved in excel, on click of hyperlink for second html
report, i dont get the second report. the same old first html report is
displayed.

Please can anyone help me. Am frustrated with this! Is it a problem of data
being cached? PLease help. Its very urgent!!!

Regards,
Spacy
 
Hi Spacy!

You should check the execution path of your program to find out what happens
at the second postback. All the data you write to the response stream after
the;

Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition", "attachment; filename=Report.xls")

....lines are streamed to that excel file. That is the key to get the correct
output.

Please step through the code to really find out what is happeneing, and
verify that you are writng the correct info from the datasource during ALL
of the postbacks, not only the first one.

And remeber

Response.Flush();
Response.Close();

when you are done writing the excel file!!

kind regards
Henrik
 
Hi Henrik!

Thanks for the prompt reply! I tried using response.flush() and
response.close(), but the same problem persists. Let me explain what am doing:

I have 2 hyperlinks. On the click of first hyperlink, ExcelReport.aspx is
executed which contains the code:
Response.ContentType = "application/vnd.ms-excel"
After this code, i write all the response.write statements that generates
the html table. The Excel Report is saved perfectly. The page does not output
anything on the screen. No problem till here!

Now when i click on the second link, Report2.aspx is called which contains
code to generate the second html table and output it on the screen. In debug
mode, every line of code is executed. But the screen is blank. The new html
table is not displayed.

I know that probably am missing something silly. Could you please help ????

Cheers..
Spacy
 
Finally I got atleast some headaway with this awful problem!
I found that this problem of the new html report not being displayed
after saving the first report to excel, occurs on only certain clients.
I was testing the code on the web server, and it wasnt working.
But on some clients, IT WORKS PERFECTLY!!!!!!!!!!

Anyone knows why????

Thanks in advance.

Regards,
Spacy
 
Back
Top