Avoid using Javascrpt to Go back to previous page with asp.net WebForms
And in most cases this will be enough to handle all cases for example when you worked with ASP.NET MVC, PHP, Python but be carefull from using it with ASP.NET WebForms.
We have a page: Page1.aspx and there is an asp:button, Now when you click on the button and get back on Page1.aspx, in this situation your previous page is still you Page1.aspx
There are another complex secnarios that i faced during my working days using this way for example:
You have Page1.aspx worked as file explorer and loads Sharepoint document library data.
So the solution with Asp.Net WebForms is to use ViewState and Request.UrlReferrer:
protected void Page_Load(object sender, EventArgs e)
if( !IsPostBack )
ViewState["RefUrl"] = Request.UrlReferrer.ToString();
protected void BtnBackToPreviousPage_Click(object sender, EventArgs e)
object refUrl = ViewState["RefUrl"];
if (refUrl != null)