How I would call a C# function from javascript?
<p>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:</p>

<pre><code>Response.Write(@"
    &lt;script language='javascript'&gt;
    var msg=confirm('Your new document has been created.\nPress OK to go there now, or Cancle to create another document.');
    if (msg==true) {&lt;%=redirect()%&gt;;}
    else {&lt;%=clearForm()%&gt;;}
    &lt;/script&gt;
");

protected void redirect(object sender, EventArgs e)
{
    Response.Redirect("myPage.aspx");
}

protected void clearForm(object sender, EventArgs e)
{
    //More code here//
}
</code></pre>

<p>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 <code>if</code> statement</p>

<p>My first idea was not to give the user an option, and to simply use:</p>

<pre><code>Response.Write(@"&lt;script language='javascript'&gt;alert('Your new document has been created.');&lt;/script&gt;");
Response.Redirect("TaskPanel.aspx");
</code></pre>

<p>But when I tried this, the page did not wait for the user to click OK before redirecting, and hence made it pointless.</p>
