转自 http://www.cnblogs.com/vipsoft/p/3298299.html

protected void Page_Load(object sender, EventArgs e)
{
ScriptManager sm = Page.Master.FindControl("ScriptManager1") as ScriptManager;
if (sm != null)
{
foreach (GridViewRow item in gvInvoiceHistory.Rows)
{
LinkButton lbtnTemp = item.FindControl("btnInvoiceNumber") as LinkButton;
if (lbtnTemp != null)
{
sm.RegisterPostBackControl(lbtnTemp);
}
}
}
} protected void btnInvoiceNumber_OnClick(object sender, EventArgs e)
{
LinkButton btnTemp = sender as LinkButton;
if (btnTemp != null)
{
var path = ConfigurationManager.AppSettings["InvoicePdfPath"];
var fileName = btnTemp.Text.Trim() + ".pdf";
if (!FileHandler.DownLoadFile(path, fileName))
{
var msg = GetLocalResourceObject("InvoiceIsNotAvailable").ToString();
ScriptManager.RegisterStartupScript(upMain, upMain.Page.GetType(), "DownLoadFile", string.Format("alert('{0}');", msg), true); //如果不存在就跳转,参见 http://www.cnblogs.com/vipsoft/p/3627683.html
      //string url = "http://www.vipsoft.com.cn";
      //ResponseRedirect.Redirect(Response, url, "_blank", "'toolbar=0,scrollbars=1,status=0,menubar=0,resizable=1,top=0,left=0,height=800,width=1000");} }
}
} //Updatepanel 会有异常 参考下面的链接查看下载方法
public static bool DownLoadFile(string path,string fileName)
{
bool result = false;
string filePath = HttpContext.Current.Server.MapPath(path + fileName);
if (File.Exists(filePath))
{
FileInfo fileInfo = new FileInfo(filePath);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
HttpContext.Current.Response.AddHeader("Content-Length", fileInfo.Length.ToString());
HttpContext.Current.Response.AddHeader("Content-Transfer-Encoding", "binary");
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
HttpContext.Current.Response.WriteFile(fileInfo.FullName);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
result = true;
}
return result;
}

ScriptManager1 放在 MasterPage中,查找 ScriptManager1 时,
Page.Master.FindControl("ScriptManager1") as ScriptManager;

FileHandler文件下载:http://www.cnblogs.com/vipsoft/p/3521958.html

如果不存在就跳转,参见 http://www.cnblogs.com/vipsoft/p/3627683.html

UpdatePanel无法导出下载文件的更多相关文章

  1. thinkphp3.2.3 excel导出,下载文件,包含图片

    关于导出后出错的问题 https://segmentfault.com/q/1010000005330214 https://blog.csdn.net/ohmygirl/article/detail ...

  2. post方式实现导出/下载文件

    项目需求: 前端需要传入过多的参数给后端,get地址栏不行,只能接受post方式去导出数据 1.get的下载方式 通常下载方式如下: let url = xxxx.action?a=xx&b= ...

  3. NET MVC FileResult 导出/下载 文件/Excel

    参考http://www.cnblogs.com/ldp615/archive/2010/09/17/asp-net-mvc-file-result.html 1.引入NPOI 2.代码 using ...

  4. C# 指定物理目录下载文件,Response.End导致“正在中止线程”异常的问题

    FileHandler http://www.cnblogs.com/vipsoft/p/3627709.html UpdatePanel无法导出下载文件: http://www.cnblogs.co ...

  5. 把页面上的图表导出为pdf文件,分享一种请求下载文件的方法

    最近客户提出一个需求,就是把页面上的图表导出为pdf文件. 找了很多资料.终于有了点头绪.最主要是参考了HighCharts的做法.http://www.hcharts.cn/ 实现原理:把页面图表的 ...

  6. JS前端创建CSV或Excel文件并浏览器导出下载

    长期以来,在做文件下载功能的时候都是前端通过ajax把需要生成的文件的内容参数传递给后端,后端通过Java语言将文件生成在服务器,然后返回一个文件下载的连接地址url.前端通过location.hre ...

  7. 数据库数据导出CSV文件,浏览器下载

    直接上代码: def download(request): # 从数据库查询数据 data_list = Info.objects.all() # 定义返回对象 response = HttpResp ...

  8. Java POI导出Excel不弹框选择下载路径(下载文件不选择下载路径,默认) Chrome

    在Chrome浏览器中,Java导出Excel文件时,浏览器弹出提示框,需要选择下载路径 在Chrome中的高级设置中,把“下载前询问每个文件的保存位置”去掉就解决了 DEEPLOVE(LC)

  9. php导出内容到txt并自动弹出下载文件

    php将内容保存到txt文件中,并自动弹出下载文件窗口的方法: $id=array('我爱学习网http://www.5ixuexiwang.com','汇享在线工具箱http://tool.huix ...

随机推荐

  1. Codeforces Round #169 (Div. 2)

    A. Lunch Rush 模拟. B. Little Girl and Game 因为可以打乱顺序,所以只关心每种数字打奇偶性. 若一开始就是回文,即奇数字母为0或1种,则先手获胜. 若奇数字母大于 ...

  2. IntelliJ IDEA 的 20 个代码自动完成的特性

    http://www.oschina.net/question/12_70799 在这篇文章中,我想向您展示 IntelliJ IDEA 中最棒的 20 个代码自动完成的特性,可让 Java 编码变得 ...

  3. MATLAB 绘图时的相关心得

    matlab中如何调整legend的位置? legend('sinx',-1); %----位于图形框外面-----------------------legend('sinx',0);------- ...

  4. 10天学会phpWeChat——第六天:实现新闻的后台管理

    通过前面五讲的系列教程,我们完成了一个简单模块的前端发布.列表展示.详情展示.实际生产环境中,所有前台的数据都会有对应的后台操作进行统筹管理.我们称之为后台管理系统. 今天,我们开始<10天学会 ...

  5. bash shell,调用ffmpeg定期截图

    #!/bin/bash #获取当前目录中所有m3u8文件,并 var=$(ls |grep '.m3u8'|cut -d '.' -f1) #死循环 = ] do #循环每个文件 for stream ...

  6. MVC 下 JsonResult 的使用方法(JsonRequestBehavior.AllowGet)【转】

    MVC 默认 Request 方式为Get. actionpublic JsonResult GetPersonInfo(){var person = new{Name = "张三" ...

  7. Process的Waitfor() 引起代码死锁

    Java用process调用c#的exe后,process.waitfor(). exe执行会停在某处.据说是waitfor引起的exe子线程死锁. 先存一个链接 http://yearsaaaa12 ...

  8. linux下shell编写九九乘法表

    主要语法:类似    1x2       echo   $((1*2)) for 变量 in 值1 值2 值3 ;do linux命令或者语句done

  9. .NET的Cookie相关操作

    using System; using System.Collections.Generic; using System.Text; using System.Web; namespace Comm ...

  10. Tomcat启动报错 Could not reserve enough space for object heap

    报错信息: Error occurred during initialization of VM Could not reserve enough space for object heap Coul ...