I want to run confirm dialog from code behind. I searched google and what I found is only where message is predefined and where confirm dialog is linked to button onclick event. I can't link my confirm dialog to onclick event, because I need to check the scenario in codebehind and ask user if he wants to continue.
I have 1 button and about 10 different scenarios (with different questions for each one of them), where I want to ask user, if he wants to continue. If he press OK, then I want to continue my code, otherwise I want to cancel.
I create some javascript function
<script type="text/javascript">
function Confirm() {
var hidden = document.getElementById("<%=HiddenField1.ClientID %>");
if (confirm("Test?")) {
hidden.value = "ok";
window.location.replace("PrijavaIzpit.aspx");
} else {
hidden.value = "cancel";
}
}
</script>
which I call from code behind
Page.ClientScript.RegisterStartupScript(GetType(), "msgbox", "Confirm();", true);
But problem is, this code only runs, if I put return
after the line where I call javascript function.
Is it the right idea? How should I do that? Is it possible with javascript?