?
Solved

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

Posted on 2004-11-26
5
Medium Priority
?
338 Views
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.
      //
      InitializeComponent();
      base.OnInit(e);
    }

    /// <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);
    }
    #endregion

    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);
      Page.Controls.Add(lictl);
      // 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,
Steve
0
Comment
Question by:StevenK
  • 2
3 Comments
 
LVL 28

Expert Comment

by:mmarinov
ID: 12679988
Hi StevenK,

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


Regards!
B..M
mmarinov
0
 

Author Comment

by:StevenK
ID: 12680023
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....
Steve
0
 
LVL 28

Accepted Solution

by:
mmarinov earned 500 total points
ID: 12680278
StevenK,

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

Regards!
B..M
mmarinov
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

840 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