[英]Reload user control after download file
在我的Webform项目中的一种表单中,有一个用户控件。 这是我要执行的操作,当用户单击此用户控件中的“下载”按钮时:
我尝试了这种解决方案,但是用户控件没有重新加载。这是onclick事件的主体:
Response.Redirect("~/Handlers/DownloadFile.ashx?FilePath=CourseFiles/" + _secondFilePath, false);
_secondFilePath = string.Empty;
CourseDB.ChangeCourseStep(DB.CurrentUser.ID, _lastUnpassedCourseInfo.CourseID, (int)Data.Enums.CourseStep.SecondPartFilesDownloaded);
Response.AddHeader("Refresh", "3; url=~/Profile/SalesEngineeringCourse.aspx");
Response.End();
这是HttpHandler的主体:
public void ProcessRequest(HttpContext context)
{
string filePath = HttpContext.Current.Request.QueryString["FilePath"];
string fileName = filePath.Split('\\').Last();
string fileType = filePath.Split('.').Last();
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.ClearContent();
response.Clear();
response.ContentType = fileType;
response.AddHeader("Content-Disposition",
"attachment; filename = " + fileName);
response.TransmitFile(System.Web.HttpContext.Current.Server.MapPath("~") + filePath);
response.Flush();
}
public bool IsReusable
{
get
{
return false;
}
}
有什么解决办法吗?
下载开始后无法刷新页面,因为下载开始时服务器已经发送了标头,因此您唯一的选择是使用一些javascript。我建议以下内容:1-更改db中的相关记录(用于更改用户状态)2-使用javascript在新窗口中下载文件(请参阅ScriptManager.RegisterStartupScript以实现此目的)3-刷新页面中的数据以显示新状态如果需要更多说明,我可以为您制作一些代码示例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.