单击链接按钮(下载)并单击其他按钮仍在下载文件 [英] When clicking the linkbutton(download) and I click the other button is still downloading the file

查看:83
本文介绍了单击链接按钮(下载)并单击其他按钮仍在下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我的代码有问题,我上传并下载后。它下载文件,但之后我点击其他按钮仍然下载文件。你能帮我吗。这是我的代码



我尝试了什么:



这是我的代码来查看文件。

if(lblFile.Text!=)

{

trAttachedFile.Visible = true;

lbtnDownload.PostBackUrl =〜/ Download.aspx?file =+ lblFile.Text;

}

else

{

trAttachedFile.Visible = false;

}





And这是我下载文件的代码(Download.aspx)



private bool StartDownload()

{

if(DownloadID!=)

{

string downloadPath = WebConfigurationManager.AppSettings [SubPic]。ToString()+ DownloadID;

FileInfo downloadFile = new FileInfo(downloadPath);



if(downloadFile.Exists)

{

回复.Clear();

Response.AddHeader(内容 - 处置,附件; filename =+ downloadFile.Name);

Response.AddHeader(Content-Length,downloadFile.Length.ToString());

Response.ContentType =application / octet-stream;

Response.WriteFile(downloadFile.FullName);

Response.End();

返回true;

}

}

返回false;

}

Hi guys im having problem on my codes, after i upload the and download it. It downloads the file but after that i click the other button is still download the file. Can you help me please. and here's my codes

What I have tried:

This is my code to view the file.
if (lblFile.Text != "")
{
trAttachedFile.Visible = true;
lbtnDownload.PostBackUrl = "~/Download.aspx?file=" + lblFile.Text;
}
else
{
trAttachedFile.Visible = false;
}


And here's my code to download the file(Download.aspx)

private bool StartDownload()
{
if (DownloadID != "")
{
string downloadPath = WebConfigurationManager.AppSettings["SubPic"].ToString() + DownloadID;
FileInfo downloadFile = new FileInfo(downloadPath);

if (downloadFile.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + downloadFile.Name);
Response.AddHeader("Content-Length", downloadFile.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(downloadFile.FullName);
Response.End();
return true;
}
}
return false;
}

推荐答案

是的,并且?这就是应该发生的事情。下载文件的浏览器与页面上发生的其他内容是分开的操作。
Yeah, and? That's what is supposed to happen. The browser downloading a file is separate operation from everything else going on on the page.


这篇关于单击链接按钮(下载)并单击其他按钮仍在下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆