11

hi I have an asp button which is created using the following code:

<asp:Button ID="btnBack" OnClientClick='javascript:history.back()' runat="server" Text="back">
</asp:Button>

However, now the javascript doesn't work to go a history back. On the other hand, if I make an alert() it works...why. Why is it not working to go a history back?

Jongware
  • 22,200
  • 8
  • 54
  • 100
Marc
  • 2,659
  • 3
  • 34
  • 41

3 Answers3

26

Try with return false at end:

 <asp:button id="btnBack" runat="server" text="Back" 
OnClientClick="JavaScript: window.history.back(1); return false;"></asp:button>
TStamper
  • 30,098
  • 10
  • 66
  • 73
0

Try:

parent.history.back();

Or

history.go(-1)
graphicdivine
  • 10,937
  • 7
  • 33
  • 59
0

Had the same problem in DevExpress project. Using ASPxButton without initializing the property "AutoPostBack" will result in redirect to self page before any client-side function call. Try AutoPostBack="false" for the button.

Rafe
  • 395
  • 1
  • 4
  • 15