一页只能有一个服务器端 Form 标记,不是一般问题!
葫芦的世界 2006-12-04 09:17:30 我现在能够确认我的ASPX页面中只包含有一个:<Form runat="server">
在CS文件里有以下代码:
Response.Clear();
Response.Buffer= true;
Response.Charset="gb2312";
//下面这行很重要, attachment 参数表示作为附件下载,您可以改成 online在线打开
//filename=FileFlow.xls 指定输出文件的名称,注意其扩展名和指定文件类型相符,可以为:.doc || .xls || .txt ||.htm
Response.AppendHeader("Content-Disposition","attachment;filename=FileFlow.xls");
Response.ContentEncoding=System.Text.Encoding.GetEncoding("gb2312");
//Response.ContentType指定文件类型 可以为application/ms-excel || application/ms-word || application/ms-txt || application/ms-html || 或其他浏览器可直接支持文档
Response.ContentType = "application/ms-excel";
this.EnableViewState = false;
//二、定义一个输入流
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
oStringWriter.WriteLine("联系人姓名,手机号码);
SqlDataReader dr = DBHelper.ExecuteReader(sql);
while (dr.Read())
{
oStringWriter.WriteLine(dr["zhName"].ToString() + "," + dr["mobile"].ToString()
}
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
//就是下面这一行,只要在这里设置断点(Response.End())
,页面上就可以弹出保存窗口.
this.RenderControl(oHtmlTextWriter);
//在这里设置断点(Response.End()),就会出现
//System.Web.HttpException: 一页只能有一个服务器端 Form 标记 错误
Response.Write(oStringWriter.ToString());
Response.End();