0

我有一个页面,可以在单击按钮时将文档导出为 excel。我需要做的是在发送 excel 文档后刷新页面。

我正在尝试注册一个脚本,该脚本将导致页面刷新,但无法在导出到 Excel 的同时进行注册。

ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "test", "alert('Done');", True)

Response.Clear()
Response.ClearHeaders()
Response.AddHeader("Refresh", "3; url=" + Request.RawUrl)
Response.ContentType = strMimeType
Response.AddHeader("content-disposition", "attachment; filename=CompleteReport." + strFilenameExtension)
Response.BinaryWrite(bytFileContent)
Response.End()
4

2 回答 2

0

Basically this can not be done if you want it reloaded only after the file has downloaded as it it not possible to find out when that is. Also you are clearing the response out and then writing the excel so the script isn't even returned from the server. The refresh-header is not being used by the browser when downloading a file either.

What you can do is to use the aspx-page to include a script like:

function onclick() {
  window.location.href = 'loadmyfile.ashx?parameters...';

  refreshPage();
}

The above will however refresh the page immediately on click so that might not be what you are after.

于 2012-08-23T10:38:23.023 回答
0

你(们)能做到

每个请求只有一个响应

(第一个 excel 导出,第二个是刷新)。在第一个 response.end 之后,你什么也做不了。您必须以另一种方式解决excel导出问题,使用组件等。导出后您可以调用

Response.redirect("your page");
于 2012-08-23T10:45:26.490 回答