我在页面上放了一个repeater控件,这个repeater在updatepanel中,我在后台对数据进行了绑定。 protected void exportData_Click(object sender, EventArgs e)
{
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
System.IO.StringWriter stringwriter = new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter htmltextWriter = new HtmlTextWriter(stringwriter);
this.ceshi.EnableViewState = false;
this.ceshi.RenderControl(htmltextWriter); Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/ms-txt";
Response.Charset = "GB2312";
this.ceshi.Page.EnableViewState = true;
Response.AppendHeader("Content-Disposition", "online;filename=miller.txt");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.Write(stringwriter.ToString());
Response.Flush();
Response.End();
}
是这样的,但是我点击导出之后也没报错,就是没有看见导出的文件miller.txt,我昨天在搜索的时候发现这些文件页面文件都在缓存中,
这是那些网页缓冲文件的属性
http://www.google.cn/complete/search?hl=zh-CN&pq=Response.AppendHeader(%22Content-Disposition%22%2C%20%22attachment%3Bfilename%3Dmiller.xls%22)%3B&xhr=t&q=%E5%B0%86%E6%95%B0%E6%8D%AE%E6%BA%90%E5%AF%BC%E5%87%BA%E5%88%B0exc&cp=1
{
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
System.IO.StringWriter stringwriter = new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter htmltextWriter = new HtmlTextWriter(stringwriter);
this.ceshi.EnableViewState = false;
this.ceshi.RenderControl(htmltextWriter); Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/ms-txt";
Response.Charset = "GB2312";
this.ceshi.Page.EnableViewState = true;
Response.AppendHeader("Content-Disposition", "online;filename=miller.txt");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.Write(stringwriter.ToString());
Response.Flush();
Response.End();
}
是这样的,但是我点击导出之后也没报错,就是没有看见导出的文件miller.txt,我昨天在搜索的时候发现这些文件页面文件都在缓存中,
这是那些网页缓冲文件的属性
http://www.google.cn/complete/search?hl=zh-CN&pq=Response.AppendHeader(%22Content-Disposition%22%2C%20%22attachment%3Bfilename%3Dmiller.xls%22)%3B&xhr=t&q=%E5%B0%86%E6%95%B0%E6%8D%AE%E6%BA%90%E5%AF%BC%E5%87%BA%E5%88%B0exc&cp=1
解决方案 »
- jquery问题
- 远程服务器返回错误: (500) 内部服务器错误。在线等
- 如何改善网站打开速度慢的问题
- 请问如何对dataset 往里追加数据呢 100分送上
- 请问有谁知道当IIS 和SQL SERVER不在同一台电脑上,要求使用WINDOWS验证,ASP。NET怎样访问数据库?
- 把内容存储为文件的问题
- 急急急!有没有高手知道如何给Login控件设置DefaultButton?
- 新手报到,送分!
- 問個很菜的ASP.NET的問題 ?
- 在调试验证页面时出现错误!!Help!
- 网站发布后,运行messagebox出现的错误
- 关于网站间session共享问题,web1已经把session保存到数据库,web2怎样读取这个session呢?
把updatepanel控件去掉就可以了。
1. 把 exportData 按钮放到 UpdatePanel 外面,加上 diplay:none 样式进行隐藏,像这样:
<asp:Button ID="exportData" runat="server" style="display:none" OnClick="exportData_Click" />2. 把原来放 exportData 按钮的地方,替换成HTML的button
<button onclick="<%= Page.ClientScript.GetPostBackEventReference(exportData, "") %>" >导出</button>另外还有很多办法,比如把UpdatePanel的ChildrenAsTriggers属性设为false,再手工指定Triggers。还可以在exportData_Click事件中用Response.Redirect重定向到本页,并且加上类似export=true这样的参数,在Page_Load中判断这个参数,如果发现有则执行导出操作,这样就可以从Ajax PostBack中跳出来。
建议换种方式实现这种静态刷新的效果。如果repeater不需要静态刷新的话,可以把repeater放到updatePanel外面