下载文件后重新加载用户控件
Reload user control after download file
在我的 webform 项目中的一个表单中,有一个用户控件。这就是我想要做的 当用户点击此用户控件中的 "download" 按钮时:
- 下载文件
- 更改数据库中的相关记录(用于更改用户状态)
- 重新加载该用户控件(或整个表单)以根据新状态显示信息。
我尝试 this solution 但用户控件不是 reload.This 是 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;
}
}
有解决办法吗?
下载开始后无法刷新页面,因为服务器已经在下载开始时发送了 header,你唯一的选择是使用一些 javascript 我会建议如下:
1 - 更改数据库中的相关记录(用于更改用户状态)
2 - 使用 javascript 在新的 windows 中下载文件(参见 ScriptManager.RegisterStartupScript 实现)
3 – 刷新页面中的数据以显示新状态如果您需要更多解释,我可以为您制作一些代码示例
在我的 webform 项目中的一个表单中,有一个用户控件。这就是我想要做的 当用户点击此用户控件中的 "download" 按钮时:
- 下载文件
- 更改数据库中的相关记录(用于更改用户状态)
- 重新加载该用户控件(或整个表单)以根据新状态显示信息。
我尝试 this solution 但用户控件不是 reload.This 是 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;
}
}
有解决办法吗?
下载开始后无法刷新页面,因为服务器已经在下载开始时发送了 header,你唯一的选择是使用一些 javascript 我会建议如下: 1 - 更改数据库中的相关记录(用于更改用户状态) 2 - 使用 javascript 在新的 windows 中下载文件(参见 ScriptManager.RegisterStartupScript 实现) 3 – 刷新页面中的数据以显示新状态如果您需要更多解释,我可以为您制作一些代码示例