C# :Response.End() 后页面按钮等功能全部失效的解决办法
2011-12-13 10:31
295 查看
我要说的这个问题,在我的项目中是这样发生的,因为项目需要,需要在页面中对数据进行导出为一个excel文件。执行代码如下:
this.Page.Response.ClearContent();
this.Page.Response.ContentEncoding = System.Text.Encoding.UTF8;
this.Page.Response.ContentType = "application/vnd.ms-excel; charset=utf-8";
this.Page.Response.AddHeader("Content-Disposition", "attachment;filename=" + reportname + DateTime.Today.ToString("MMddyyyy") + ".xls");
this.Page.Response.Write(ExportUtil.DataTableToExcelTable(dt, displayColumnNames, null));
this.Page.Response.End();
运行成功,但是页面上的导出按钮不能再次点击。
后搜寻国内外网站,都说要用Popup的方式来解决。很气馁。终于在一个国外的论坛里发现了解决办法。
现将解决方式如下:
string beforeSubmitJS = "/nvar exportRequested = false; /n";
beforeSubmitJS += "var beforeFormSubmitFunction = theForm.onsubmit;/n";
beforeSubmitJS += "theForm.onsubmit = function(){ /n";
beforeSubmitJS += "var returnVal = beforeFormSubmitFunction(); /n";
beforeSubmitJS += "if(exportRequested && returnVal) {_spFormOnSubmitCalled=false; exportRequested=false;} /n";
beforeSubmitJS += "return returnVal; /n";
beforeSubmitJS += "}; /n";
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alterFormSubmitEvent", beforeSubmitJS, true);
注册javascript程序,然后再按钮提交时发送一个参数:
this._btnSubmit.Attributes["onclick"] = "javascript:exportRequested=true;";
这样可以解决这个问题。
原理:页面按钮提交时会调用一个内置的方法并修改一个内置变量_spFormOnSubmitCalled,我们通过按钮来调用方法重置
这个参数的值,达到系统检索页面时,一直默认为未提交状态。
this.Page.Response.ClearContent();
this.Page.Response.ContentEncoding = System.Text.Encoding.UTF8;
this.Page.Response.ContentType = "application/vnd.ms-excel; charset=utf-8";
this.Page.Response.AddHeader("Content-Disposition", "attachment;filename=" + reportname + DateTime.Today.ToString("MMddyyyy") + ".xls");
this.Page.Response.Write(ExportUtil.DataTableToExcelTable(dt, displayColumnNames, null));
this.Page.Response.End();
运行成功,但是页面上的导出按钮不能再次点击。
后搜寻国内外网站,都说要用Popup的方式来解决。很气馁。终于在一个国外的论坛里发现了解决办法。
现将解决方式如下:
string beforeSubmitJS = "/nvar exportRequested = false; /n";
beforeSubmitJS += "var beforeFormSubmitFunction = theForm.onsubmit;/n";
beforeSubmitJS += "theForm.onsubmit = function(){ /n";
beforeSubmitJS += "var returnVal = beforeFormSubmitFunction(); /n";
beforeSubmitJS += "if(exportRequested && returnVal) {_spFormOnSubmitCalled=false; exportRequested=false;} /n";
beforeSubmitJS += "return returnVal; /n";
beforeSubmitJS += "}; /n";
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alterFormSubmitEvent", beforeSubmitJS, true);
注册javascript程序,然后再按钮提交时发送一个参数:
this._btnSubmit.Attributes["onclick"] = "javascript:exportRequested=true;";
这样可以解决这个问题。
原理:页面按钮提交时会调用一个内置的方法并修改一个内置变量_spFormOnSubmitCalled,我们通过按钮来调用方法重置
这个参数的值,达到系统检索页面时,一直默认为未提交状态。
相关文章推荐
- C# :Response.End() 后页面按钮等功能全部失效的解决办法
- eWebEditor在ie9下按钮功能失效的解决办法
- C# WinForm webBrowser 内嵌网页的按钮的OnClientClick事件的return false 在webBrowser中绑定onclick事件后 失效 的变通解决办法
- C# WinForm webBrowser 内嵌网页的按钮的OnClientClick事件的return false 在webBrowser中绑定onclick事件后 失效 的变通解决办法
- eWebEditor在ie9下按钮功能失效的解决办法;
- eWebEditor在ie9下按钮功能失效的解决办法
- eWebEditor在ie9下按钮功能失效的解决办法
- js_html_input中autocomplete="off"在chrom中失效的解决办法 使用JS模拟锚点跳转 js如何获取url参数 C#模拟httpwebrequest请求_向服务器模拟cookie发送 实习期学到的技术(一) LinqPad的变量比较功能 ASP.NET EF 使用LinqPad 快速学习Linq
- asp.net 导出excel 表之后 按钮 页面控件失效不可用,没反应的解决办法。
- SharePoint中用Response第一次导出Excel后所有页面按钮不起作用解决办法
- 一个页面很长下面有提交按钮,提交后还在原位置的简单解决办法
- 解决response.write()css失效的问题办法
- DISCUZ网站DIY后,导致DIY功能失效,无法在前台删除已创建的DIY功能解决办法
- ios7自定义返回按钮后,右滑返回功能失效解决方法
- ubuntu usb接口在开机后全部失效,只有重启才能恢复的解决办法
- SharePoint工程中用Response生成Excel以后页面按钮失效问题
- Chrome浏览器所有页面全部崩溃的解决办法
- viewpager通过点击按钮方式切换界面失效的解决办法
- Tomcat 7 ueditor上传功能失效的解决办法
- 新浪微博 分享功能 handleWeiboResponse(intent, response); 不回调的解决办法