【问题标题】:how to cancel enter key event for file download after file is being downloaded in asp.net using C#使用C#在asp.net中下载文件后如何取消文件下载的输入键事件
【发布时间】:2016-09-14 06:33:55
【问题描述】:

我有一个带有搜索框的页面,当用户按回车键时将触发搜索(我正在通过回车键在IsPostBack上检查此搜索。然后当搜索完成时,用户可以点击下载在搜索中显示的文件的链接上。

问题是当用户点击链接并返回搜索框时,回车键再次触发下载文件。

文件下载后如何清除该事件,再次触发IsPostBack

注意:我在 Gridview 控件中使用 Linkbutton 控件来触发文件下载。

文件下载代码:

 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string[] arg = new string[2];
            if (e.CommandName == "DownloadFile")
            {
                arg = e.CommandArgument.ToString().Split(';');
                string fileName = arg[0];
                string path = arg[1];
                Response.Clear();
                Response.ContentType = "Application/octet-stream";
                Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(fileName));
                Response.TransmitFile(Server.MapPath(path + fileName));
                Response.End();
            }
        }

【问题讨论】:

    标签: c# asp.net ispostback transmitfile


    【解决方案1】:

    问题 [已解决] 我所要做的就是将文本框的AutoPostBack 属性设置为true

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多