UpdatePanel无法导出下载文件
转自 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无法导出下载文件的更多相关文章
- thinkphp3.2.3 excel导出,下载文件,包含图片
关于导出后出错的问题 https://segmentfault.com/q/1010000005330214 https://blog.csdn.net/ohmygirl/article/detail ...
- post方式实现导出/下载文件
项目需求: 前端需要传入过多的参数给后端,get地址栏不行,只能接受post方式去导出数据 1.get的下载方式 通常下载方式如下: let url = xxxx.action?a=xx&b= ...
- NET MVC FileResult 导出/下载 文件/Excel
参考http://www.cnblogs.com/ldp615/archive/2010/09/17/asp-net-mvc-file-result.html 1.引入NPOI 2.代码 using ...
- C# 指定物理目录下载文件,Response.End导致“正在中止线程”异常的问题
FileHandler http://www.cnblogs.com/vipsoft/p/3627709.html UpdatePanel无法导出下载文件: http://www.cnblogs.co ...
- 把页面上的图表导出为pdf文件,分享一种请求下载文件的方法
最近客户提出一个需求,就是把页面上的图表导出为pdf文件. 找了很多资料.终于有了点头绪.最主要是参考了HighCharts的做法.http://www.hcharts.cn/ 实现原理:把页面图表的 ...
- JS前端创建CSV或Excel文件并浏览器导出下载
长期以来,在做文件下载功能的时候都是前端通过ajax把需要生成的文件的内容参数传递给后端,后端通过Java语言将文件生成在服务器,然后返回一个文件下载的连接地址url.前端通过location.hre ...
- 数据库数据导出CSV文件,浏览器下载
直接上代码: def download(request): # 从数据库查询数据 data_list = Info.objects.all() # 定义返回对象 response = HttpResp ...
- Java POI导出Excel不弹框选择下载路径(下载文件不选择下载路径,默认) Chrome
在Chrome浏览器中,Java导出Excel文件时,浏览器弹出提示框,需要选择下载路径 在Chrome中的高级设置中,把“下载前询问每个文件的保存位置”去掉就解决了 DEEPLOVE(LC)
- php导出内容到txt并自动弹出下载文件
php将内容保存到txt文件中,并自动弹出下载文件窗口的方法: $id=array('我爱学习网http://www.5ixuexiwang.com','汇享在线工具箱http://tool.huix ...
随机推荐
- Scala笔记整理
使用类型参数化数组(Array) 创建java.math.BigInteger实例: var big = new java .math.BigInteget("12345678") ...
- js代码实现下拉菜单
效果 js代码: <script type="text/javascript"> function ShowSub(li) {//函数定义 var subMenu = ...
- 『U3D学习』破坏神回忆图<二>技能系统
- java的VO和PO的用途
最近在搞一个项目,用到了 springMVC,加深了我对VO和PO的理解,有感而发. 1 写在之前的提示 VO == Value Object PO == Persistant Object VO对应 ...
- 学习css中得与惑
css的学习分享 所学的css知识看多,会看懂.这只是在实践中发现的问题: 一. ???h1比div还大 h1上下有边距 为什么浮动不了 (现不知道) 二. css写了 表现不出来.... ...
- POJ做题笔记:1000,1004,1003
1000 A+B Problem 题目大意:输入两个数a和b,输出他们的和. 代码: #include <stdio.h> int main() { int a, b; while (sc ...
- mybatis——使用mapper代理开发方式
---------------------------------------------------------------generatorConfig.xml------------------ ...
- js键盘事件全面控制详解
js键盘事件全面控制 主要分四个部分第一部分:浏览器的按键事件第二部分:兼容浏览器第三部分:代码实现和优化第四部分:总结 第一部分:浏览器的按键事件 用js实现键盘记录,要关注浏览器的三种按键事件 ...
- OpenGL角轴
概述 轴旋转 角轴 概述 OpenGL旋转矩阵 旋转角度直接影响OpenGL GL_MODELVIEW矩阵的前三列,准确地说是向左.向上与向前三轴元素.例如,如果一沿X轴的单位向量(1,0,0)与任一 ...
- NetflixOSS:Hollow正式发布
http://www.infoq.com/cn/articles/netflixoss-hollow-officially-released "如果你能 非常有效地 缓存 一切 ,那么通 ...