raklos
raklos

Reputation: 28545

create a back button that uses javascript or respose.redirect

Im using asp.net c# (webforms)

I want to add a back button to my page. (you land on this page if you incorrectly fill in a form).

if javascript is enabled i want to go back via javascript, but if it is disabled i'll just do a response.redirect("~/home.aspx")...

how can i implement this? is it 2 buttons? how can i hide the other in the 2 different states if so.

thanks

Upvotes: 1

Views: 385

Answers (2)

derek
derek

Reputation: 4886

<asp:Button OnClick="serverMethod" OnClientClick="return(jsMethod);" runat="server" ID="redirectButton" Text="Back" />

on the button, but set the OnClientCLick to: return(javascriptredirect()); and the OnClick to your button click event handler in your code behind.

if javascript is enabled, it will do the javascript redirect, if not enabled the page will post back and you can do your OnClick code behind method whic can to the response.redirect. You can also return false from your function to prevent the postback from occurring such as the case with setting the OnClientClick="return(confirm('Are you sure?'));"

Upvotes: 1

Related Questions