LiteralControl - awaiting response from ...... ? (ASP.NET / C#)

We've got ourselves a situation that we can't seem to resolve.
We have some instances within our web forms (ASP.NET with C# code).
What we want to be able to do is halt the processing of code via
means of a LiteralControl (through javascript) and await a response,
catch it and react accordingly ..

Let's suppose that we generate a 'confirm' message via javascript -
we want to continue the code to halt, and then if the user clicks OK
continue, otherwise stop processing the code that follows :

Our code so far is as follows :

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace WebAppX
  /// <summary>
  /// Summary description for WebForm1.
  /// </summary>
  public class WebForm1 : System.Web.UI.Page
    protected System.Web.UI.WebControls.Button Button1;
    protected System.Web.UI.WebControls.TextBox TextBox1;
    protected System.Web.UI.WebControls.TextBox TextBox2;

    private void Page_Load(object sender, System.EventArgs e)
      // Put user code to initialize the page here

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
      // CODEGEN: This call is required by the ASP.NET Web Form Designer.

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
     private void InitializeComponent()
      this.Button1.Click += new System.EventHandler(this.Button1_Click);
      this.Load += new System.EventHandler(this.Page_Load);

    private void Button1_Click(object sender, System.EventArgs e)
      TextBox1.Text = "";
      TextBox2.Text = "";
      TextBox1.Text = "First Text";
      string jStr = @"<script language='JavaScript'>confirm('Continue ?');</script>";
      LiteralControl lictl = new LiteralControl(jStr);
      // I want my code to stop here and await response from the 'confirm' above
      TextBox2.Text = "Second Text";

Any help would be greatly appreciated ...
Thanks in advance,
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi StevenK,

unfortunately these are client and server side scripts
the way you can do this is by reposting the page after the confirmation

StevenKAuthor Commented:
You're right in the sense that the issue is between client and server side.
How do you mean by 'reposting the page after the confirmation' ?
We need to be in a position where (by clicking a button) we start some logic processing... If a condition is met we then present the user with a (confirm) message... Depending on how the user responds to this message we want to do different things... If we click 'OK' the code logic should continue to flow... If we click 'Cancel' the code should stop flowing and return focus to the working web page.
Can we do such a thing ?
Thanks again....

as i said you have to separate the logic
when the user cick a button the page is submitted
when you have to show a confirmation use RegisterStartupscript
in the registered client function use confirm () method and if the user clicks ok submit the page by document.forms[0].submit() and operate as you wish
if the user click Cancel do not submit the page

if you want to show something after clicking OK or cancel on the scree you can submit the page in both scenarios but before submit the page add the user selection ( OK/Cancel) to a hidden field so you can undesrtand in the code behind what you should do


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.