Click here to Skip to main content
15,902,910 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I`m making website using ASP.NET

When I build a code about button click event, I want to make like this.

1. Modify cancel button press, confirm message showed "Are your Sure?"
2. If clicked yes, call javascript history back method, moved to previous page
3. if clicked no, nothing happened.

How can I make that?? Please help me.

What I have tried:

<asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClientClick="JavaScript:window.history.back(1); return false;"/>
Posted
Updated 22-Aug-16 21:53pm
v2

try using a function

JavaScript
function myfunc() {
          if( confirm('are you sure?'))
              window.history.back(1);
      }


ASP.NET
<asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClientClick=" myfunc(); return false;" />
 
Share this answer
 
Comments
RydenChoi 24-Aug-16 0:48am    
Thank you. it works perfectly and I use it many ways...Great!!
Karthik_Mahalingam 24-Aug-16 0:53am    
:) welcome
Hello you can do like so:

var result = confirm("Are you sure?");

if(result)
{
window.location.history.back(1);
}
 
Share this answer
 
v2
Comments
RydenChoi 24-Aug-16 5:01am    
Thank you for your comment :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900