文件下载后如何重新加载页面 [英] How to reload a page after file download

查看:87
本文介绍了文件下载后如何重新加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我知道这是一个重复的问题。但是我尝试了几种方法却找不到它。

我有一个数据网格和一个文件下载按钮。下载文件后,我需要再次重新加载页面。

怎么做。任何帮助都将非常感谢。



我尝试过:



Hi all,
I know this is a duplicate question. But I have tried several methods but couldn't find it.
I have a datagrid and a file download button. After the file is downloaded I need the page to be reloaded again.
How to do this.Any help will be really appreciated.

What I have tried:

try
         {


             string user = Session["user"].ToString();
             var document = new Document(PageSize.A4, 50, 30, 20, 20);

             var output = new MemoryStream();
             var writer = PdfWriter.GetInstance(document, output);
             document.Open();
             //var titleFont = FontFactory.GetFont("Arial", 18, Font.BOLD);
             var titleFont = FontFactory.GetFont("Verdana", 16, Font.BOLDITALIC, new Color(125, 88, 15));



             var itemsTable = @"<table>";
             itemsTable += string.Format("<font style=\"font-family: Verdana\" size=\"2\"><tr><td ><table border=\"0\"><tr><td  align=\"Left\" colspan=\"6\"><img src='" + pdfheader + "' height=\"30px\" width=\"100px\" style=border-style: none></td></tr><tr><td colspan=\"7\" align=\"Center\" style=\"background-color:#FFA28A;color:#000000;margin:100px;\" Height=\"30px\" Valign=\"middle\">Quotation NO : " + QotationID + "</td></tr></table></td> </tr>");
             for (int j = 0; j < grd_datalist.Rows.Count; j++)
             {
                   itemsTable += string.Format("<font style=\"font-family: Verdana\" size=\"2\"><tr><td ><table border=\"0\"><tr><td colspan=\"7\" align=\"Center\" style=\"background-color:#ffffff;color:#000000;margin:100px;\" Height=\"30px\" Valign=\"left\"> "+grd_datalist.Rows[j].Cells[2].Text  + " : " + grd_datalist.Rows[j].Cells[3].Text  + "</td></tr></table></td></tr>");
             }


             itemsTable += "<br/><br/><tr><td></td></tr><tr><td align=\"center\"  style=\"color:#000000;background-color:#FF0000;padding:5px;\" valign=\"middle\" >xxx Email info@ccc.ae Toll Free: 800 872 432 584 Phone+971 4 235 9116</td></tr></font></table>";
             ArrayList htmlarraylist = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(new StringReader(itemsTable), null);
             //add the collection to the document
             for (int k = 0; k < htmlarraylist.Count; k++)
             {

                 document.Add((IElement)htmlarraylist[k]);
             }

             document.Close();

             Response.ContentType = "application/pdf";
             Response.AddHeader("Content-Disposition", string.Format("attachment;filename=Schedule-{0}.pdf", QotationID));
             Response.BinaryWrite(output.ToArray());
             ScriptManager.RegisterStartupScript(this, this.GetType(), "onload", "javascript:location.reload(true);", true);


         }
         catch (Exception exp)
         {

             Alert.Show(exp.Message.ToString());

         }
         finally
         {

             grd_view.DataBind();
             UpdatePanel2.Update();
             Session["gdxml"] = "";
             ClearTest();
             grd_datalist.DataBind();
             //quolists();
         }
     }



这是我的文件下载代码。请帮帮我。


This is my file download code.Please help me.

推荐答案

下载后无法重新加载页面,无法知道下载何时完成或文件是否完全下载。您应该在新标签中发起下载,因此如果您的下载是链接,则添加target =_ blank



You can't reload the page after a download and there is no way of knowing when the download completes or if the file is downloaded at all. You should instigate the download in a new tab, so if your download is a link then add target="_blank"

<a href="downloadfile.aspx?ID=123" target="_blank">download</a>





然后您可以重新加载单击该链接的页面。您还没有解释如何启动下载,因此很难给出具体的解决方案。



You could then reload the page on the click of that link. You haven't explained how you instigate the download so it's hard to give a specific solution.


参考我的文章/提示 ASP.NET导出Excel - 显示/隐藏加载图像 [ ^ ]

做一些稍微修改一下代码,不要在下载后隐藏图像,只需使用位置重载()方法重新加载页面 [ ^ ]
refer my Article/Tip ASP.NET Export Excel - Show/Hide Loading Image[^]
do some slight modification to the code in such a way that instead of hiding the image after download, just reload the page with Location reload() Method[^]


这篇关于文件下载后如何重新加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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