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

Posted on 2004-11-26
Last Modified: 2006-11-17
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,
Question by:StevenK
    LVL 28

    Expert Comment

    Hi StevenK,

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


    Author Comment

    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....
    LVL 28

    Accepted Solution


    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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now