导出到Excel时刷新标签 [英] Refreshing a label when exporting to Excel
问题描述
我有几个将某些表导出到Excel的按钮.我有一个标签控件,可用来报告任何错误.
当我单击一个按钮并且没有要导出的记录时,我会相应地设置标签的文本.但是,当我单击另一个按钮并有要导出的记录时,会生成电子表格,但标签值不会更改,因为即使我尝试将标签的文本设置为找到的记录数.
Excel导出功能没有什么特别的-它只是通常的配置HttpResponse
,添加合适的标题,将DataGrid
控件呈现为HTMLTextWriter
,然后执行Response.Write()
Response.End()
.
有人可以帮忙吗?
谢谢:)
Hi,
I''ve got a couple of buttons which export some tables to Excel. I have a label control which I use to report any errors.
When I click a button and there''s no records to export, I set my label''s text accordingly. However, when I then click on the other button and there are records to export, the spreadsheet is generated but the label value doesn''t change as no postback seems to occur even though I try to set the label''s text to the number of records found.
There''s nothing special about the Excel export functionality - it''s just the usual configure an HttpResponse
, add a suitable header, render a DataGrid
control to an HTMLTextWriter
and do a Response.Write()
followed by a Response.End()
.
Can anyone help?
Thanks :)
推荐答案
这里发生的是,您的Excel导出将响应发送到客户端浏览器.
由于mime类型,浏览器知道要下载的是附件,而不是要显示的网站.
因此,它将打开新的响应并将int保存到本地磁盘,但不会重新加载当前页面.
老实说,我不确定是否/如何实现这一目标;我会尝试尝试一些AJAX,更新面板等...
干杯
Uwe
What happens here is, that your Excel export sends a response to the client browser.
Due to the mime type, the browser knows that is is an attachment do download, rather than a website to display.
So it opens the new response and saves int to your local disk, but does not reload the current page.
To be honest, I am unsure whether/how to achieve this; I would try experimenting with some AJAX, Update Panels, and the like...
Cheers
Uwe
这篇关于导出到Excel时刷新标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!