Last Updated: February 25, 2016
·
2.803K
· ordepdev

Redirect to previous page

The trick is to store the Request.UrlReferrer in ViewState during the page load.

protected void Page_Load(object sender, EventArgs e)
{    
    if (Page.IsPostBack) return;
    ViewState["PreviousPageUrl"] = Request.UrlReferrer.ToString();
}

protected void btnBack_Click(object sender, EventArgs e)
{
    Page.Response.Redirect(ViewState["PreviousPageUrl"]
        .ToString());
}