代码 protected void Page_Load(object sender, EventArgs e)
{
//页面数据生成前在前台显示等待页面
Response.Write("<div id='mydiv' >");
Response.Write("_");
Response.Write("</div>");
Response.Write("<script>mydiv.innerText = '';</script>");
Response.Write("<script language=javascript>;");
Response.Write("var dots = 0;var dotmax = 10;function ShowWait()");
Response.Write("{var output; output = '正在装载页面';dots++;if(dots>=dotmax)dots=1;");
Response.Write("for(var x = 0;x < dots;x++){output += '·';}}");
Response.Write("mydiv.innerHTML = '<img src=loading.gif>';");
Response.Write("function StartShowWait(){mydiv.style.visibility = 'visible'; ");
Response.Write("window.setInterval('ShowWait()',1000);}");
Response.Write("function HideWait(){mydiv.style.visibility = 'hidden';");
Response.Write("window.clearInterval();}");
Response.Write("StartShowWait();</script>");
Response.Flush();
//页面数据生成前在前台显示等待页面 if (Session.Contents["user"] == null)
{
Response.Redirect("Login.aspx");
}
if (!Page.IsPostBack)
{
this.fund_account.Text = Session.Contents["fund_account"].ToString();
this.Text_start.Text = Session.Contents["Text_start"].ToString();
this.Text_end.Text = Session.Contents["Text_end"].ToString();
initData();
}
}//导出excel代码
protected void CreateExcel(GridView gv)
{
Response.Clear();
Response.Buffer = true;
Response.Charset = "GBK";
Response.AppendHeader("Content-Disposition", "attachment;filename=Data.xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GBK");
Response.ContentType = "application/ms-excel";
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
gv.RenderControl(oHtmlTextWriter); Response.Output.Write(oStringWriter.ToString());
Response.Flush();
Response.End();
}
按钮调用
protected void Button2_Click(object sender, EventArgs e)
{
CreateExcel(GV_cover);
}
代码运行正常,在数据页面生成前有等待图 等页面数据加载完后生成数据页面,但是一运行导出代码 就弹出错误“服务器无法在发送 HTTP 标头之后设置内容类型”如果把
//页面数据生成前在前台显示等待页面
代码注释的话 导出功能恢复正常请问怎么有什么好的方案可以解决吗?
{
//页面数据生成前在前台显示等待页面
Response.Write("<div id='mydiv' >");
Response.Write("_");
Response.Write("</div>");
Response.Write("<script>mydiv.innerText = '';</script>");
Response.Write("<script language=javascript>;");
Response.Write("var dots = 0;var dotmax = 10;function ShowWait()");
Response.Write("{var output; output = '正在装载页面';dots++;if(dots>=dotmax)dots=1;");
Response.Write("for(var x = 0;x < dots;x++){output += '·';}}");
Response.Write("mydiv.innerHTML = '<img src=loading.gif>';");
Response.Write("function StartShowWait(){mydiv.style.visibility = 'visible'; ");
Response.Write("window.setInterval('ShowWait()',1000);}");
Response.Write("function HideWait(){mydiv.style.visibility = 'hidden';");
Response.Write("window.clearInterval();}");
Response.Write("StartShowWait();</script>");
Response.Flush();
//页面数据生成前在前台显示等待页面 if (Session.Contents["user"] == null)
{
Response.Redirect("Login.aspx");
}
if (!Page.IsPostBack)
{
this.fund_account.Text = Session.Contents["fund_account"].ToString();
this.Text_start.Text = Session.Contents["Text_start"].ToString();
this.Text_end.Text = Session.Contents["Text_end"].ToString();
initData();
}
}//导出excel代码
protected void CreateExcel(GridView gv)
{
Response.Clear();
Response.Buffer = true;
Response.Charset = "GBK";
Response.AppendHeader("Content-Disposition", "attachment;filename=Data.xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GBK");
Response.ContentType = "application/ms-excel";
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
gv.RenderControl(oHtmlTextWriter); Response.Output.Write(oStringWriter.ToString());
Response.Flush();
Response.End();
}
按钮调用
protected void Button2_Click(object sender, EventArgs e)
{
CreateExcel(GV_cover);
}
代码运行正常,在数据页面生成前有等待图 等页面数据加载完后生成数据页面,但是一运行导出代码 就弹出错误“服务器无法在发送 HTTP 标头之后设置内容类型”如果把
//页面数据生成前在前台显示等待页面
代码注释的话 导出功能恢复正常请问怎么有什么好的方案可以解决吗?
解决方案 »
- 此页的状态信息无效,可能已损坏。 这个是什么错 ?
- linq中怎么格式化从数据库中取出来的日期
- 把几个用户访问量比较大的项目合并起来做在一个项目里,会不会增加系统堵塞连接超时的机率啊?
- 怎么让图片热点显示简介信息
- DataGrid里如何获得模版列中CheckBox选中时本行其它项的值?最好不要使用循环,而是直接取值.
- 有没有人有asp.net 1.1版的WebParts控件?
- 请问各位朋友一个ASP.NET中大文本存储问题
- 怎样禁止页面使用缓存!
- 请问动易CMS怎么做网站通用搜索引擎?
- 请问怎样设置才能使这个网页打开一点显示一点呢?另外,我的WebForm中有一个Reset按钮(用于清除信息),一个Button(用于提交并做处理),怎样在
- ASP.net <a href ="">标签里嵌套做eval绑定
- 在线客服问题
Response.Write("_");
Response.Write("</div>");
Response.Write("<script>mydiv.innerText = '';</script>");
Response.Write("<script language=javascript>;");
Response.Write("var dots = 0;var dotmax = 10;function ShowWait()");
Response.Write("{var output; output = '正在装载页面';dots++;if(dots>=dotmax)dots=1;");
Response.Write("for(var x = 0;x < dots;x++){output += '·';}}");
Response.Write("mydiv.innerHTML = '<img src=loading.gif>';");
Response.Write("function StartShowWait(){mydiv.style.visibility = 'visible'; ");
Response.Write("window.setInterval('ShowWait()',1000);}");
Response.Write("function HideWait(){mydiv.style.visibility = 'hidden';");
Response.Write("window.clearInterval();}");
Response.Write("StartShowWait();</script>");
Response.Flush();
这段放在 Response.Write("<div id='mydiv' >");
Response.Write("_");
Response.Write("</div>");
Response.Write("<script>mydiv.innerText = '';</script>");
Response.Write("<script language=javascript>;");
Response.Write("var dots = 0;var dotmax = 10;function ShowWait()");
Response.Write("{var output; output = '正在装载页面';dots++;if(dots>=dotmax)dots=1;");
Response.Write("for(var x = 0;x < dots;x++){output += '·';}}");
Response.Write("mydiv.innerHTML = '<img src=loading.gif>';");
Response.Write("function StartShowWait(){mydiv.style.visibility = 'visible'; ");
Response.Write("window.setInterval('ShowWait()',1000);}");
Response.Write("function HideWait(){mydiv.style.visibility = 'hidden';");
Response.Write("window.clearInterval();}");
Response.Write("StartShowWait();</script>");
Response.Flush();
这段需要放在if (!Page.IsPostBack)里 就能解决