0

This should be so simple, and indeed I have found many solutions on SO and elsewhere. But nothing I do seems to work. This is what I currently have:

<asp:ImageButton ID="BackButton" runat="server" ImageUrl="Images/redAbort.png"
    OnClientClick="backClick()" CssClass="TVMback-button" />

And:

function backClick(sender) {                                    
    history.back(1);
    return false;
}

But the page just refreshes. I get to this page using Javascript (via document.location), by the way. And I really do want to implement a "back" function here, rather than targeting a preset URL, as I could end up here from various sources. But even when I do try to set document.location to the URL of the previous page, nothing happens.

So I guess I've missed something stupid simple.

I have tried a bazillion of combinations though. Including prefacing history with document. and window., as well as trying .go(-1), etc.

I have also tried returning false, true, nothing at all. I have tried to return Santa Claus and the shoes I bought for my girlfriend in Raleigh, NC back in 2012, as they were a size too big. But nothing seems to work.

Frédéric Hamidi
  • 240,249
  • 39
  • 455
  • 462
Christofer Ohlsson
  • 2,987
  • 4
  • 36
  • 54
  • Browsers come with a nice big back button. Just let users use that. There's no point in trying to duplicate its functionality. – Quentin May 23 '14 at 08:42
  • What Quentin said, plus [(this)](http://stackoverflow.com/questions/3893963/asp-net-onclientclick-return-false-doesnt-work) – Abhitalks May 23 '14 at 08:43
  • Quentin: Maybe I should have been clearer on that: This application is designed to run on an embedded system with touch screen input only. No toolbar etc. – Christofer Ohlsson May 23 '14 at 08:46

2 Answers2

1

You are not propagating the value returned by backClick() from the event handler.

You should write:

<asp:ImageButton ID="BackButton" runat="server" ImageUrl="Images/redAbort.png"
    OnClientClick="return backClick();" CssClass="TVMback-button" />

Also note that history.back() does not take an argument, so you only have to write:

function backClick()
{
    history.back();
    return false;
}
Frédéric Hamidi
  • 240,249
  • 39
  • 455
  • 462
1

You could just use html. No need for the ASP.

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