response 后刷新页面,点击按钮后,禁用该按钮
一,正常的点击按钮后,将其灰显,全部执行完毕再正常显示。
this.btnSave.Attributes.Add("onclick", "if (typeof(Page_ClientValidate)=='function' && Page_ClientValidate() == false)return false;document.all('" + btnSave.ClientID + "').disabled=true;if(typeof(__doPostBack)=='function')" + this.GetPostBackEventReference(btnSave) + ";");
btnSave为按钮ID。
二,
response 后刷新页面
先要求点按钮生成文件,同时按钮变灰,文件生成好直接打开该文件,按钮可用。
注意:internet安全设置,
下载——文件下载(启用)
文件下载——文件下载的自动提示(启用)
一、第一种方法,用iframe:
1,给按钮增加点击后变灰,页面刷新变可用属性。
打开文件代码如下:
//写出文件
System.Text.Encoding encoding = System.Text.Encoding.GetEncoding("gb2312");
HttpResponse response = HttpContext.Current.Response;
response.HeaderEncoding = encoding;
response.Charset = encoding.HeaderName;
response.Clear();
response.ContentEncoding = encoding;
response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(pdfFile.Name));
response.AddHeader("Content-Length", pdfFile.Length.ToString());
response.ContentType = "application/pdf";
response.WriteFile(pdfFile.FullName);
HttpContext.Current.ApplicationInstance.CompleteRequest();
打开文件
要弹出文件,页面请求会立刻结束。所以这时你把按钮的任何控制都不会执行。
2,aspx页面:增加一个iframe
<iframe id="ifrm_popMessage" src="" frameborder="0" scrolling="no" align="middle"
style="position: absolute; z-index: 100; display: none; border: 1px #62A3D2 solid;">
</iframe>
3,aspx页面:增加JS脚本:
////打开文件
function OpenPdfFile() {
document.getElementById('ifrm_popMessage').src = "OpenPdfFile.aspx?Rnd" + Math.random();
}
4,生成文件结束后增加如下代码:
ScriptManager.RegisterStartupScript(this.Page, ClientScript.GetType(), "myscript", "<script>OpenPdfFile();</script>", false);
5,OpenPdfFile 页面代码:
/// <summary>
/// 用来生成PDF文件
/// </summary>
public partial class Admin_IEData_OpenPdfFile : System.Web.UI.Page
{
/// <summary>
/// 页面加载
/// </summary>
protected void Page_Load(object sender, EventArgs e)
{
DirectoryInfo di = new DirectoryInfo(Server.MapPath("~/File/"));
string strFileName = string.Format("{0}({1}){2}.pdf", di.FullName, SessionOperate.getLoginName(), "ddpdf");
FileInfo pdfFile = new System.IO.FileInfo(strFileName);
WriteOutFile(pdfFile);
} #region 写出文件
/// <summary>
/// 写出文件
/// </summary>
/// <param name="pdfFile">文件对象</param>
/// <returns>返回是否成功</returns>
protected bool WriteOutFile(FileInfo pdfFile)
{
//写出文件
System.Text.Encoding encoding = System.Text.Encoding.GetEncoding("gb2312");
HttpResponse response = HttpContext.Current.Response;
response.HeaderEncoding = encoding;
response.Charset = encoding.HeaderName;
response.Clear();
response.ContentEncoding = encoding;
response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(pdfFile.Name));
response.AddHeader("Content-Length", pdfFile.Length.ToString());
response.ContentType = "application/pdf";
response.WriteFile(pdfFile.FullName);
HttpContext.Current.ApplicationInstance.CompleteRequest();
return true;
}
#endregion
}
Iframe页面代码
二、这个方法比较好,再加一个隐藏按钮,点打印,把按钮变灰(加按钮属性实现),然后显示一个隐藏的字(正在打印……)结束后按钮恢复,字隐藏(加按钮属性实现)在打印后台代码里增加JS触发隐藏按钮onclik事件,隐藏按钮事件里写加载打印文件代码。
1、前台代码
<div style="text-align: center; margin-top: 5px;">
<cc1:JETButton ID="btnOk" runat="server" Text="打印" OnClick="btnOk_Click" />
<div id="exporting" style="display:none;"><br /><font color="#ff0000" size="4.5px">数据正在打印中,请稍等……</font></div>
</div>
<div style="display:none;">
<cc1:JETButton ID="btnDownload" runat="server" Text="下载" CssClass="hide" OnClick="btnDownload_Click" />
</div>
前台代码
2、 void Page_Load(object sender, EventArgs e)
this.btnOk.Attributes.Add("onclick", "if (typeof(Page_ClientValidate)=='function' && Page_ClientValidate() == false)return false;document.getElementById('" + btnOk.ClientID + "').disabled=true;document.getElementById('exporting').style.display='block';if(typeof(__doPostBack)=='function'){" + this.GetPostBackEventReference(btnOk) + ";}");
3、打印按钮onclick代码
//生成打印
ClientScript.RegisterStartupScript(this.GetType(), "exported", "document.getElementById('" + btnOk.ClientID + "').disabled=false;document.getElementById('exporting').style.display='none';document.getElementById('" + btnDownload.ClientID + "').click();", true);
打印按钮onclick代码
4、点击下载按钮
/// <summary>
/// 点击下载按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnDownload_Click(object sender, EventArgs e)
{
//TODO:此处写下载打印合并的PDF
DirectoryInfo di = new DirectoryInfo(Server.MapPath("~/File/ExportTemplate/ExcelTmp/"));
string strFileName = string.Format("{0}({1}){2}.pdf", di.FullName, SessionOperate.getLoginName(), "pdf文件");
FileInfo pdfFile = new System.IO.FileInfo(strFileName);
WriteOutFile(pdfFile);
}
点击下载按钮
response 后刷新页面,点击按钮后,禁用该按钮的更多相关文章
- Ajax请求数据与删除数据后刷新页面
1.ajax异步请求数据后填入模态框 请求数据的按钮(HTML) <a class="queryA" href="javascript:void(0)" ...
- Ajax异步调用http接口后刷新页面
使用Ajax的目的就是提高页面响应速度,无需同步调用,无需整个页面刷新.这里直接在html中使用js来实现: 先获取XMLHttpRequest对象 var xmlHttp; //创建一个xmlHtt ...
- 用HTTP状态码实现提交表单后刷新页面不重复提交
正常情况下,表单提交后如果用户刷新页面会重复提交表单,有些情况下我们不希望表单重复提交,利用HTTP协议中的307状态码重定向页面可以实现这个目的.实例如下: 表单页面代码: <form act ...
- <asp:TextBox><asp:LinkButton><input button>调用后台方法后刷新页面
<asp:TextBox><asp:LinkButton>服务器控件,执行后台方法,会回调加载js,相当于页面重新加载,刷新页面 <input button>不能直 ...
- vue打包后刷新页面报错:Unexpected token <
前言 今天遇到了一个很怪的问题,在vue-cli+webpack的项目中,刷新特定页面后页面会变空白,报错为index.html文件中Unexpected token <. 怪点一是开发环境没有 ...
- ajax删除数据后刷新页面
代码如图: 理解: 发送请求后删除name 属性为 name 的data;用rem .remove删除: 删除后找到页面上app的数量:定义page = len/12+1; 找到当前页是哪一页,如果l ...
- HTML或者JSP页面--执行完某事件后刷新页面,重置表单,清空数据
在提交表单或者执行某个事件之后,如果需要重置表单(即清空表单里的数据) 可以执行下面代码来完成 方式一: self.location.href="userController.do?goAd ...
- 使用element-ui的el-menu导航选中后刷新页面保持当前选中
<el-menu :default-active=‘$route.path‘ :router=‘true‘ :unique-opened=‘true‘ :default-openeds=&quo ...
- LayUi前端框架删除数据缓存问题(解决删除后刷新页面内容又会显示问题)
form.on('submit(mySearch)', function(data){ table.reload('userTable', {//就会读取后台数据,重新加载: page: { curr ...
随机推荐
- ruby 疑难点之—— attr_accessor attr_reader attr_writer
普通的实例变量 普通的实例变量,我们没法在 class 外面直接访问 #普通的实例变量,只能在 class 内部访问 class C1 def initialize(name) @name = nam ...
- 【简单dp+模拟】hdu-5375(2015多校#7-1007)
给你一个二进制数,,每一位有一个权值,让你转格雷码,求所对应格雷码位为1的权值的和:二进制位中的某些位为?,你需要给这些问号赋值使得到的和最大. 首先你得知道二进制转格雷码的规则,即格雷码位为[二进制 ...
- Mac下批量打包
两种方式: 第一种:有源码 这种方式比较 简单.利用ant打包.直接shell脚本修改 配置渠道号的文件.我们目前是用的umeng的.在AndroidManifest.xml里.提供一个简单的修改渠道 ...
- Ajax具体使用
Ajax在注册页面经常使用,当注册用户是用户名必须唯一时,要使用ajax获取表单中你输入的内容, 然后将这个数据利用XMLHttpRequest对象请求一个php文件,这个php文件接收到信息,查询数 ...
- oracle中比较两表表结构差异和数据差异的方法
在工作中需要完成这么一个需求:比较两个表的表结构是否形相同,并找出差异.比较两个表中的数据是否相同,并找出差异数据? 分析:由于表结构中字段比较多,手工比较很浪费时间,而且不能保证不出错误.对于 ...
- Java之绘制二次曲线
前面已经介绍过绘制方法.这里不再赘述. 画一下草图来看看:灰色表示X值,红色表示Y值. 在这里要值得注意的是:当我们把它们的坐标在纸上画出来时,就会觉得“有问题”了,你看A(60,20,120,100 ...
- ADO.NET笔记(一)XML导入导出和数据库
数据导出成XML文件 #region 数据导出成XML文件 string sql = "select Id, CallerNumber, TelNum, StartDateTime, End ...
- Cocos2d-x手机游戏开发中-组合动作
动作往往不是单一,而是复杂的组合.我们可以按照一定的次序将上述基本动作组合起来,形成连贯的一套组合动作.组合动作包括以下几类:顺序.并列.有限次数重复.无限次数重复.反动作和动画.动画我们会在下一节介 ...
- Quartz.NET快速上手第一课(官网文档翻译)
Quartz.NET快速上手第一课(官网文档翻译) 原文链接 在你使用调度者(scheduler)之前,你需要对它进行实例化(谁能猜到这呢?).在实例化scheduler时候,你需要使用ISchedu ...
- (转)实战Memcached缓存系统(5)Memcached的CAS程序实例
1. 非CAS 首先看一个不是CAS的Memcached程序实例.实例的问题原型,见上一篇博文. 程序实例: package com.sinosuperman.memcached; import ja ...