Get previous page name in asp.net

says that I have 3 pages (origin1.aspx) / (origin2.aspx) / (destination.aspx), and I have a control that represents the back button, its functionality to get from which page it was called. and once clicking, redirects back to the caller’s original page, I searched the Internet and found a lot of big and simple ideas like queryString and sessions, but unfortunately I should not use any of them, so any help?

+4
source share
3 answers

You can use a little JavaScript:

<asp:button id="m_BackButton" runat="server" onclientclick="goBack()" /> <script type="text/javascript"> function goBack(){ history.go(-1); } </script> 
+2
source
+4
source

You can go from all users to javascript, but if you need to go to the server:

I do not think it is really beautiful, but he is doing his job. Also gives you a lot of energy.

First, on the main page, we have such code to set the page name in the session

 if (!IsPostBack) { if (Request.UrlReferrer != null && Request.UrlReferrer.AbsoluteUri != null) { Session.Add("UrlReferrer", Request.UrlReferrer.AbsoluteUri); } } 

Then we have the ashx walking arm with simple code like this.

 using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace WebApplication1 { /// <summary> /// Summary description for Backhandler /// </summary> public class Backhandler : IHttpHandler { private const string DEFAULTPAGE = "MyDdefaultreturnpage.aspx"; public void ProcessRequest(HttpContext context) { string previousPage = context.Session["UrlReferrer"] as String ?? DEFAULTPAGE; context.Response.Redirect(previousPage); } public bool IsReusable { get { return false; } } } } 

All buttons in the application can redirect backhandler.ashx files. Yuo could even put this in your css.

Hope this helps.

0
source

All Articles