SoutTran
asked on
Cancel button to go back to previous page
Hi Everyone,
I tried using the below javascripts on my vb code behind for both the page_load and btCancel_Click event, it does not take me back to the previous page.
btCancel.Attributes.Add("o nClick", "javascript:history.back() ;")
OR
btCancel.Attributes.Add("o nClick", "javascript:history.go(-1) ;")
What else can I try?????
The Cancel button is part of a form to gather user input data and submit them if users desired to but they want to cancel out this page, they can click on the cancel button to go back to the previous page where they come from.
Thanks in advance
I tried using the below javascripts on my vb code behind for both the page_load and btCancel_Click event, it does not take me back to the previous page.
btCancel.Attributes.Add("o
OR
btCancel.Attributes.Add("o
What else can I try?????
The Cancel button is part of a form to gather user input data and submit them if users desired to but they want to cancel out this page, they can click on the cancel button to go back to the previous page where they come from.
Thanks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I was using the HTML button before, but since I need to reference this control in the codebehind it gave me error with regards to Object not instantiated. So I tried to go back using the below HTML button, it works. I don't know why it didn't worked before. I'll need to do some more testing.
<input id="btCancel" onclick="Javascript:histor y.back();" type="button" value="Cancel" name="btCancel">
Anyway, thanks so much!
<input id="btCancel" onclick="Javascript:histor
Anyway, thanks so much!
ASP.NET buttons (in the System.Web.UI.Webcontrols family) are ALL automatically SUBMIT buttons. That means when you click them, they submit the page. This action takes precedence over any onclick events that you code. However, you can cancel the submit by returning a value of false from YOUR onclick code.
So your original idea would work, but you need to add a return false.
btCancel.Attributes.Add("o nClick", "javascript:history.back() ; return false;")
So your original idea would work, but you need to add a return false.
btCancel.Attributes.Add("o
href="javascript:history.b
instead of asp.net button you can just have html button or <a link as shown above...