0

How can I easily popup a message and get back OK or Cancel, with one line of .vb ASP.NET code as easily as this pops up an OK box?

ClientScript.RegisterStartupScript(Me.GetType(), "AlertScript", "alert('" & message & "');", True)

1 Answer 1

0

The shortest way is using confirm() function:

' using single if
Me.Page.ClientScript.RegisterStartupScript(Me.GetType(), "ConfirmScript", "if(confirm('" & message & "')) { // do something }", True)

' using if-else
Me.Page.ClientScript.RegisterStartupScript(Me.GetType(), "ConfirmScript", "if(confirm('" & message & "')) { // do something } else { // do other thing }", True)

Or calling a function which containing confirm():

JS

<script>
    function showConfirm(msg) {
        if (confirm(msg)) {
            // do something
        } else {
            // do other thing
        }
    }
</script>

Code behind

Me.Page.ClientScript.RegisterStartupScript(Me.GetType(), "ConfirmScript", "showConfirm('" & message & "')", True)

If you want to receive returned value (OK/Cancel) in server-side, you can store return value in a hidden field, handle OnClick event from the control which displays confirm box and use Request.Form as provided in this issue.

Sign up to request clarification or add additional context in comments.

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.