1

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.

0

3 Answers 3

1

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;
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.