使用 UpdatePanel 从流中下载文件

Download file from stream using UpdatePanel

我们正在尝试像这样从字节流下载文件:

            byte[] arrBytes = x.Result;
            Response.ClearContent();
            Response.ClearHeaders();
            Response.Buffer = true;
            Response.ContentType = file.MimeType;
            Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Title);
            Response.OutputStream.Write(arrBytes, 0, arrBytes.Length);
            Response.Flush();

它在没有更新面板的情况下工作,但使用更新面板时同样无法下载。请提出一些解决方法。

可能您正在使用<asp:AsyncPostBackTrigger>,请将其替换为<asp:PostBackTrigger>