我有一个Button,按下的事件名为Download_Click,
在按下後会下载档案,同时把Button与Button所在的DIV_AA隐藏起来:protected void Download_Click(object sender, EventArgs e)
{
//第一段
Response.Clear();
Response.ClearHeaders();
Response.AppendHeader("Content-Disposition", "attachment; filename=AA.doc");
Response.TransmitFile(“C:\\AA.doc”);
Response.End();
//第二段
Download.Visible = false;
string js;
js = "<script>try{ document.getElementById('DIV_AA').style.visibility = 'hidden';}catch(e){}</script>";
ScriptManager.RegisterClientScriptBlock(this, js.GetType(), "", js, false);
}我试了几次,如果只留第二段,那麽Button与DIV_AA会成功隐藏,
如果只留第一段,也能成功跑出下载视窗并下载档案,
但第一段与第二段都存在时,却只跑出下载视窗,Button与DIV_AA并不会隐藏,
是两段程式相冲突吗?
在按下後会下载档案,同时把Button与Button所在的DIV_AA隐藏起来:protected void Download_Click(object sender, EventArgs e)
{
//第一段
Response.Clear();
Response.ClearHeaders();
Response.AppendHeader("Content-Disposition", "attachment; filename=AA.doc");
Response.TransmitFile(“C:\\AA.doc”);
Response.End();
//第二段
Download.Visible = false;
string js;
js = "<script>try{ document.getElementById('DIV_AA').style.visibility = 'hidden';}catch(e){}</script>";
ScriptManager.RegisterClientScriptBlock(this, js.GetType(), "", js, false);
}我试了几次,如果只留第二段,那麽Button与DIV_AA会成功隐藏,
如果只留第一段,也能成功跑出下载视窗并下载档案,
但第一段与第二段都存在时,却只跑出下载视窗,Button与DIV_AA并不会隐藏,
是两段程式相冲突吗?
Response.Clear()之后还会输出之前内容到客户端吗?
<input type="button" onclick="hideDIV();window.opem('下载页面','_blank')"
string js;
js = "<script>try{window.open('Download.aspx?user=" + User.Value,'_blank');document.getElementById('DIV_AA').style.visibility = 'hidden';}catch(e){}</script>";
ScriptManager.RegisterClientScriptBlock(this, js.GetType(), "", js, false);然後在Download.aspx的Page_Load中加入
Response.Clear();
Response.ClearHeaders();
Response.AppendHeader("Content-Disposition", "attachment; filename=AA.doc");
Response.TransmitFile(“C:\\AA.doc”);
Response.End();
但问题又来了,
我在localhost可以执行,可以下载(确认下载的视窗有出现),
但上传到网站後,按下Button後,
下载的Download.aspx会瞬间消失,连确认下载的视窗都没出现,
这又是怎麽回事呢?