简体   繁体   中英

ASP.NET Confirmation dialog on server side

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.

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;

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>

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM