asp button and history back onclientclick

28.1k Views Asked by At

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?

3

There are 3 best solutions below

1
On BEST ANSWER

Try with return false at end:

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

Try:

parent.history.back();

Or

history.go(-1)
0
On

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.