In my asp.net application I have used JavaScript confirm box for user confirmation. Here is the code:
EDIT :
Simple solution use javascript and call OnClientClick
<script type="text/javascript">
function confirm() {
if (confirm('This Contract Have a Pre-Renewed,Please Delete that Contract First')) {
return true;
}
else {
return false;
}
}
</script>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" OnClientClick="return
confirm()"/>
By using javascript confirm method you only decide, whether you want to continue or not - so it is ok that your Button1_Click
method is called only when user clicks ok.
What you trying to do is quite different. I would suggest to get rid of ASP.NET Button control and use "common" HTML link like:
<a href="#" id="decideLink">Click me</a>
And then in javascript
document.getElementById('decideLink').onclick = function()
{
if(proceed) {
// do something here
} else {
// do something different
}
}
To call code-behind method from javascript, check this article about calling web methods from javascript