文件下载后,Document Ready无法工作

Document Ready not working after file download

本文关键字:工作 Ready Document 文件下载      更新时间:2023-09-26

我有一个Aspx页面。点击按钮,我正在从服务器下载一个文件。

用于下载文件的服务器端代码

   byte[] data = GetBytes();
    //Sets the Content Type and FileName 
    HttpContext.Current.Response.ContentType = "plan/text";
    HttpContext.Current.Response.AddHeader("Content-Disposition",  string.Format("attachment;filename={0}", "Error.txt"));
    //Writes the Content in HttpResponse
    //to enable downloading the file.
    HttpContext.Current.Response.Clear();
    HttpContext.Current.Response.BinaryWrite(data);
    HttpContext.Current.Response.End();

Aspx页面上的Javascript代码

$(document).ready(function () {
 alert(1);
});

此警报在加载第一页时显示。但在回发文件下载后,它没有显示警报。提前感谢。

这是因为部分Postback。您需要使用PageRequestManager来设置请求处理程序。然后,请求处理程序也将在部分回发时执行。

请参阅此答案

请参阅此答案