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