Ali_dotNet
Ali_dotNet

Reputation: 3279

ASP.net simulate browser back button

I'm working on my ASP.NET web project using VS2010, C#, I'm inserting a hyperlink in my page, labeled as BACK, and I want it to act like browser back button, how should I implement it? what is the easiest way? how should I set its navigateURL property? thanks

Upvotes: 11

Views: 49813

Answers (6)

Siafa
Siafa

Reputation: 1

something like this should do

<button>
    @Html.ActionLink("Back", "Index", "Students (your controller name here)", new { id = @Model.Student.Id })</button>
ANOTHER WAY
<a asp-action="Index" asp-controller="Students" asp-route-studentId="@Model.StduentId" class="btn btn-sm btn-success">Back to List</a>

Upvotes: -2

anandd360
anandd360

Reputation: 306

Try this..

private void btnBack_Click(object sender, System.EventArgs e)
{
    string prevPage = Request.UrlReferrer.ToString();
    Response.Redirect(prevPage);
}

or

<asp:button id="btnBack" runat="server" text="Back" xmlns:asp="#unknown">
 OnClientClick="JavaScript: window.history.back(1); return false;"></asp:button>

Upvotes: 1

VladL
VladL

Reputation: 13043

If you are using JQuery, you can simply add data-rel="back" to your anchor-tag

<a data-rel="back" data-role="button" data-icon="back">Back</a>

Upvotes: 1

Chris1804505
Chris1804505

Reputation: 97

@Steve Not sure how to comment on an existing answer but... I figured that I could just for kicks say that you could always make the "button" a "linkbutton":

Upvotes: 1

Al Kepp
Al Kepp

Reputation: 5980

You don't need ASP.NET, just use this HTML/JScript code:

<a href="javascript:history.go(-1)">Back</a>

Upvotes: 14

Steve Morgan
Steve Morgan

Reputation: 13091

<asp:button id="backButton" runat="server" text="Back" 
OnClientClick="JavaScript:window.history.back(1);return false;"></asp:button>

Except that's a button, of course :-( (read the question, Steve)

Try

navigateurl="javascript:history.go(-1);"

Upvotes: 36

Related Questions