下载文件后重新加载用户控制



在我的WebForm项目中的一种形式中,有一个用户控件。这是我想在此用户控件中单击"下载"按钮时要做的:

  1. 下载文件
  2. 更改数据库中的相关记录(用于更改用户状态(
  3. 重新加载该用户控制(或整个表单(以根据新状态显示信息。

我尝试了此解决方案,但用户控件未重新加载。这是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-更改数据库中的相关记录(用于更改用户状态(2-使用JavaScript在新窗口中下载文件(请参阅ScriptManager.RegisterStartupscript以实现这一目标(3 - 在页面中的数据刷新以显示新状态,如果您需要更多说明,我可以为您做一些代码示例

最新更新