By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,384 Members | 845 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,384 IT Pros & Developers. It's quick & easy.

Asp.Net : html to excel problem

P: n/a

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


Jul 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

"Spacy" wrote:

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

Jul 21 '05 #2

P: n/a

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"
Response.AddHeader("content-disposition", "attachment; filename=Report.xls")
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

"Henrik Nordgren" wrote:
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

"Spacy" wrote:

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

Jul 21 '05 #3

P: n/a

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

"Spacy" wrote:

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"
Response.AddHeader("content-disposition", "attachment; filename=Report.xls")

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

"Henrik Nordgren" wrote:
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

"Spacy" wrote:

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

Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.