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.Redirect to previous page on Button Click using C# and VB.Net in ASP.Net<p>Hi&nbsp;nauna,</p> <p>There are two ways of do this.</p> <p>1. By setting PostBackUrl property of ASP.Net Button, LinkButton and ImageButton.</p> <p>2. By using Server.Transfer.</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><span style="text-decoration: underline;"><strong>CS.aspx</strong></span></p> <pre class="brush: html">&lt;asp:Button ID=&#34;btnResponseRedirect&#34; Text=&#34;Response Redirect&#34; runat=&#34;server&#34; /&gt; &lt;asp:Button ID=&#34;btnServerTransfer&#34; Text=&#34;Server Transfer&#34; runat=&#34;server&#34; OnClick=&#34;ServerTransfer&#34; /&gt;</pre> <p><strong><span style="text-decoration: underline;">CS.aspx.cs</span></strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { btnResponseRedirect.PostBackUrl = &#34;Default.aspx&#34;; } protected void ServerTransfer(object sender, EventArgs e) { Server.Transfer(&#34;Default.aspx&#34;); }</pre> <p><strong><span style="text-decoration: underline;">CS.aspx.vb</span></strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load btnResponseRedirect.PostBackUrl = &#34;Default.aspx&#34; End Sub Protected Sub ServerTransfer(ByVal sender As Object, ByVal e As EventArgs) Server.Transfer(&#34;Default.aspx&#34;) End Sub</pre> <p>Then you can check with&nbsp;PreviousPage property.</p> <p><strong><span style="text-decoration: underline;">Default.aspx</span></strong></p> <pre class="brush: html">&lt;asp:Button ID=&#34;btnResponseRedirect&#34; Text=&#34;Go To Previous Page Response Redirect&#34; runat=&#34;server&#34; Enabled=&#34;false&#34; /&gt; &lt;asp:Button ID=&#34;btnServerTransfer&#34; Text=&#34;Go To Previous Page Server Transfer&#34; runat=&#34;server&#34; Enabled=&#34;false&#34; /&gt;</pre> <p><strong><span style="text-decoration: underline;">Default.aspx.cs</span></strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (PreviousPage != null) { btnServerTransfer.Attributes.Add(&#34;onClick&#34;, &#34;javascript:history.back(); return false;&#34;); btnServerTransfer.Enabled = true; btnResponseRedirect.Attributes.Add(&#34;onClick&#34;, &#34;javascript:history.back(); return false;&#34;); btnResponseRedirect.Enabled = true; } } }</pre> <p><strong><span style="text-decoration: underline;">Default.aspx.vb</span></strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Not IsPostBack Then If PreviousPage IsNot Nothing Then btnServerTransfer.Attributes.Add(&#34;onClick&#34;, &#34;javascript:history.back(); return false;&#34;) btnServerTransfer.Enabled = True btnResponseRedirect.Attributes.Add(&#34;onClick&#34;, &#34;javascript:history.back(); return false;&#34;) btnResponseRedirect.Enabled = True End If End If End Sub</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><strong><span style="text-decoration: underline;"><img src="https://i.imgur.com/8SZSYGI.gif" alt="" width="297" height="144" /></span></strong></p>https://www.aspforums.net:443/Threads/725382/Redirect-to-previous-page-on-Button-Click-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/725382/Redirect-to-previous-page-on-Button-Click-using-C-and-VBNet-in-ASPNet/Mon, 07 Jan 2019 05:11:32 GMT