Reputation: 483
I have a Page which takes input from the user and then process his request on a button click. On this button click event, I need to validate the input entered by him and on certain condition show confirmation dialog box. If he clicks Yes, then I need to perform further action else return.
I have tried using
Page.ClientScript.RegisterStartupScript(this.GetType(), Constants.OpenConfirm, "confirm('Data Already Exists, do you Wish to Overwrite the existing record?')", true);
But irrespective of whether I click Yes or No it is performing the further action.
Have have tried using JavaScript method calling from server side, but that is also not working out.
Upvotes: 1
Views: 6146
Reputation: 38663
Try this way: Server side code
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Javascript", "Javascript:val()", true);
client side code
<head runat="server">
<title></title>
<script>
function val() {
if (confirm('XXXXYYYY?')) { alert("clicked yes") } else { alert("clicked No") }
}
</script>
</head>
Upvotes: 0
Reputation: 10198
Try on page_load .cs
ClientScript.RegisterStartupScript(GetType(), "Javascript",
"javascript:if(confirm('Are you sure?')) { alert('YOu have selected YES')} else{alert('you have click NO')}; ", true);
Upvotes: 0
Reputation: 24832
You need to process the result of your confirm call. So the script parameter musts be something like that:
if(!confirm('Data Already Exists, do you Wish to Overwrite the existing record?')) return false;
Upvotes: 1