ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Refresh Page when Download Button is clicked in ASP.Net<p>Hi <a class="username" rel="haocaocu">haocaocu</a>,</p> <p>Please add the below line of code at the end of OpenPDF method so that it automatically redirect you.</p> <p><span style="text-decoration: underline;">Code</span></p> <pre class="brush: csharp">Response.Redirect(Request.Url.AbsoluteUri);</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/420584/Refresh-Page-when-Download-Button-is-clicked-in-ASPNet/https://www.aspforums.net:443/Threads/420584/Refresh-Page-when-Download-Button-is-clicked-in-ASPNet/Thu, 24 Sep 2015 07:21:30 GMTRefresh Page when Download Button is clicked in ASP.Net<p>Hi dharmendr,</p> <p><span id="result_box" lang="en"><span class="hps">I</span>'ve inserted <span class="hps">into the</span> <span class="hps">line of code</span> <span class="hps">that</span> <span class="hps">it</span> <span class="hps">worked</span>, but not <span class="hps">open the</span> <span class="hps">pdf</span> <span class="hps">file</span>. <span class="hps">You</span> <span class="hps">help</span> <span class="hps">me</span> <span class="hps">with</span>. <span class="hps">Thank you</span></span></p>https://www.aspforums.net:443/Threads/420584/Refresh-Page-when-Download-Button-is-clicked-in-ASPNet/https://www.aspforums.net:443/Threads/420584/Refresh-Page-when-Download-Button-is-clicked-in-ASPNet/Thu, 24 Sep 2015 18:52:10 GMTRefresh Page when Download Button is clicked in ASP.Net<p>Hi dharmendr</p> <p><span id="result_box" lang="en"><span class="hps">I</span> <span class="hps">insert</span> <span class="hps">this code into</span> <span class="hps">methods</span> <span class="hps">OpenPDF</span> <span class="hps">end</span>, <span class="hps">it worked</span> <span class="hps">ok</span> <span class="hps atn">(</span>new <span class="hps">image</span> <span class="hps">disappears</span>) <span class="hps">but does not</span> <span class="hps">open the</span> <span class="hps">pdf</span> <span class="hps">file</span>. <span class="hps">You</span> <span class="hps">have</span> <span class="hps">no other way</span> <span class="hps">to help</span> <span class="hps">me</span> <span class="hps">with</span>. <span class="hps">Thank you!</span></span></p>https://www.aspforums.net:443/Threads/420584/Refresh-Page-when-Download-Button-is-clicked-in-ASPNet/https://www.aspforums.net:443/Threads/420584/Refresh-Page-when-Download-Button-is-clicked-in-ASPNet/Sun, 27 Sep 2015 22:28:43 GMTRefresh Page when Download Button is clicked in ASP.Net<p>Hi <a class="username" rel="haocaocu"> haocaocu</a>,</p> <p>I will get back to you.</p>https://www.aspforums.net:443/Threads/420584/Refresh-Page-when-Download-Button-is-clicked-in-ASPNet/https://www.aspforums.net:443/Threads/420584/Refresh-Page-when-Download-Button-is-clicked-in-ASPNet/Mon, 28 Sep 2015 02:07:53 GMTRefresh Page when Download Button is clicked in ASP.Net<p>Here I have created sample that will help you out.</p> <p><span style="text-decoration: underline;">HTML</span></p> <pre class="brush: html">&lt;div&gt; &lt;script type=&#34;text/javascript&#34;&gt; function Redirect() { setTimeout(function () { window.location.reload(1); }, 5000); } &lt;/script&gt; &lt;asp:GridView ID=&#34;GridView1&#34; runat=&#34;server&#34; AutoGenerateColumns=&#34;false&#34; EmptyDataText=&#34;No files uploaded&#34; OnRowDataBound=&#34;RowDataBound&#34;&gt; &lt;Columns&gt; &lt;asp:TemplateField HeaderText=&#34;File&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID=&#34;lblFileName&#34; Text=&#39;&lt;%#Eval(&#34;FileName&#34;) %&gt;&#39; runat=&#34;server&#34; /&gt; &lt;asp:HiddenField ID=&#34;hfViewed&#34; Value=&#39;&lt;%#Eval(&#34;View&#34;) %&gt;&#39; runat=&#34;server&#34; /&gt; &lt;asp:HiddenField ID=&#34;hfId&#34; Value=&#39;&lt;%#Eval(&#34;Id&#34;) %&gt;&#39; runat=&#34;server&#34; /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText=&#34;Download&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:LinkButton ID=&#34;lnkDownload&#34; Text=&#34;Download&#34; CommandArgument=&#39;&lt;%# Eval(&#34;FilePath&#34;) %&gt;&#39; runat=&#34;server&#34; OnClick=&#34;DownloadFile&#34; OnClientClick=&#34;Redirect()&#34;&gt;&lt;/asp:LinkButton&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; &lt;/div&gt;</pre> <p><span style="text-decoration: underline;">Code</span></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindGird(); } } protected void RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { ((Label)e.Row.FindControl(&#34;lblFileName&#34;)).Text += Convert.ToBoolean(((HiddenField)e.Row.FindControl(&#34;hfViewed&#34;)).Value) ? &#34;**&#34; : &#34;&#34;; } } protected void DownloadFile(object sender, EventArgs e) { string filePath = (sender as LinkButton).CommandArgument; GridViewRow row = (GridViewRow)(sender as LinkButton).NamingContainer; int fileId = Convert.ToInt32(((HiddenField)row.FindControl(&#34;hfId&#34;)).Value); UpdateFileView(fileId, true); Response.ContentType = ContentType; Response.AppendHeader(&#34;Content-Disposition&#34;, &#34;attachment; filename=&#34; + Path.GetFileName(filePath)); Response.WriteFile(filePath); Response.End(); } private void BindGird() { string constr = ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand(&#34;SELECT * FROM [FileViewTable]&#34;)) { using (SqlDataAdapter sda = new SqlDataAdapter()) { cmd.Connection = con; sda.SelectCommand = cmd; using (DataTable dt = new DataTable()) { sda.Fill(dt); GridView1.DataSource = dt; GridView1.DataBind(); } } } } } private void UpdateFileView(int fileId, bool IsViewed) { string constr = ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand(&#34;UPDATE FileViewTable SET [View] = @View WHERE [Id] = @Id&#34;)) { cmd.Parameters.AddWithValue(&#34;@Id&#34;, fileId); cmd.Parameters.AddWithValue(&#34;@View&#34;, IsViewed); cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); con.Close(); } } }</pre> <p><span style="text-decoration: underline;">Screenshot</span></p> <p><img src="https://i.imgur.com/FjgqCTT.gif" alt="" width="336" height="272" /></p>https://www.aspforums.net:443/Threads/420584/Refresh-Page-when-Download-Button-is-clicked-in-ASPNet/https://www.aspforums.net:443/Threads/420584/Refresh-Page-when-Download-Button-is-clicked-in-ASPNet/Mon, 28 Sep 2015 10:14:52 GMT