I'm trying to figure out how I would call a C# function from a javascript confirm box. i.e. If user selects 'OK' a function is called, and if user selects 'Cancel' another function is called. All the code is located in the back page, and looks as follows:
Response.Write(@"
<script language='javascript'>
var msg=confirm('Your new document has been created.\nPress OK to go there now, or Cancle to create another document.');
if (msg==true) {<%=redirect()%>;}
else {<%=clearForm()%>;}
</script>
");
protected void redirect(object sender, EventArgs e)
{
Response.Redirect("myPage.aspx");
}
protected void clearForm(object sender, EventArgs e)
{
//More code here//
}
Note that all the code within the Response.Redirect is all on one line, I just split it up here for simplicity!
Anyways, this does not work, and I cant find a solution. I've tried various different things within the if
statement
My first idea was not to give the user an option, and to simply use:
Response.Write(@"<script language='javascript'>alert('Your new document has been created.');</script>");
Response.Redirect("TaskPanel.aspx");
But when I tried this, the page did not wait for the user to click OK before redirecting, and hence made it pointless.