Click here to Skip to main content
15,905,782 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
this is my button code

ASP.NET
<asp:Button ID="Button1" runat="server" PostBackUrl="~/Transferencia.aspx"
       Text="aceptar" onclick="Button1_Click"
       onclientclick="confirm ('Do you want to cancel ?');" />


but i say ok and don't go to transferencias.aspx what i need to do.

thank for help me.
Posted
Comments
Richard C Bishop 2-Jan-14 16:15pm    
So anytime they click the button it is going to ask if they want to cancel? The logic is flawed in that.

What is your ultimate goal here?

do not add postback url. insted write a javascript function and if confirm is ok redirect to other page .


JavaScript
function movetonextpage()
{
if(confirm(are you sure you want to cancel?))
{
window.location = 'your page name';
}
else
{
return false;
}
}



call this function on the button client click.
 
Share this answer
 
Try returning false when user does not confirm.
ASP.NET
<asp:Button ID="Button1" 
         runat="server" 
         PostBackUrl="~/Transferencia.aspx"
         Text="aceptar" 
         OnClick="Button1_Click"
         OnClientClick="if ( ! UserConfirmation()) return false;" />

Use the following JavaScript.
JavaScript
function UserConfirmation() {
    return confirm("Do you want to cancel ?");
}

So, when user presses cancel, the function will return false to OnClienClickEvent and satisfies the if condition.
So, again it executes return false; inside the Event. So, PostBack does not happen.
 
Share this answer
 
try this..

ASP.NET
<asp:Button ID="Button1" runat="server"
            Text="aceptar" onclick="Button1_Click"
            onclientclick="!confirm ('Do you want to cancel ?');" />
 
Share this answer
 

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