Popup message with Buttons in Java Script in C# programming

Hello Experts,
I am looking for Popup message in C# programming.  If certain condition is true, I need the message box with 2 Buttons (Cancel and Continue).  If Cancel is clicked, it should come back to the C# steps and continue execution from the next line of the code.  Otherwise, it should skip the rest of the routine.  

Is Java Scripts is a better solution?  If so, how to do it?  Also, please let me know if you have a better idea.  Thank you a lot in advance.

Example:
--------------
if (condition == ture)
{
    Display Message Box (with Cancel and Continue buttons)
    if (Continue is clicked)
    {
         Continue processing...
    }
    else
    {
         Skip processing...
    }
}
RadhaKrishnaKiJayaAsked:
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.

Ryan ChongCommented:
yes, you can do it either at Server Side ( C# code behind validation) or via Client Side (javascript validation).

Here's an example for your references:

Server Side (Code Behind) Yes No Confirmation Message Box in ASP.Net
http://www.aspsnippets.com/Articles/Server-Side-Code-Behind-Yes-No-Confirmation-Message-Box-in-ASPNet.aspx

from the result (Yes/No) captured, we can either continue or skip the processes.
0
RadhaKrishnaKiJayaAuthor Commented:
Hello Ryan,
Thank you for your help.  The code you provided is a Button Click event.  I need exactly same thing, but inside the c# code.  Here is the example.

C# Code...
.
.
protected void btnUpdate_Click(object sender, EventArgs e)
{
      C# Code....
      .
      .
      if (condition == True)
      {
            Display Message Box (with Cancel and Continue buttons)
            if (Continue is clicked)
            {
                  Continue processing...
            }
            else
            {
                   Skip processing...
            }
      }
      else
      {
                   Skip processing...
       }
}
.
.
0
David Johnson, CD, MVPOwnerCommented:
   private void button1_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Display Message", "Application Name", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.OK)
            {
             // do something here
                label1.Text = "You Pressed OK";
            }
        else {
                return  ;
                }

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Ryan ChongCommented:
similarly, you can have a panel control in your page with Yes/ No buttons, when a button was clicked, show that panel accordingly.

Do you think that make sense to you?
0
Ryan ChongCommented:
below is a simple example using panel:

Web form: WebForm1.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <br />
        <br />
        <asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <br />
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" Display="Dynamic" ErrorMessage="Pls enter your name to proceed" ForeColor="Red" SetFocusOnError="True"></asp:RequiredFieldValidator>
        <br />
        <br />
        <asp:Button ID="btnUpdate" runat="server" OnClick="btnUpdate_Click" Text="Update" />
        <br />
        <br />
        <asp:Panel ID="Panel1" runat="server" Visible="False">
            Are you sure want to update the record?<br />
            <br />
            <asp:Button ID="btnYes" runat="server" OnClick="btnYes_Click" Text="Yes" />
            <asp:Button ID="btnNo" runat="server" OnClick="btnNo_Click" Text="No" />
            <asp:Label ID="lblProcess" runat="server" Text="Processing..." Visible="False"></asp:Label>
        </asp:Panel>
    
    </div>
    </form>
</body>
</html>

Open in new window


Code behind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnNo_Click(object sender, EventArgs e)
        {
            Panel1.Visible = false;
        }

        protected void btnYes_Click(object sender, EventArgs e)
        {
            lblProcess.Visible = true;
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            Panel1.Visible = true;
        }
    }
}

Open in new window

0
käµfm³d 👽Commented:
Um, actually no you cannot do it that way...well, not the way you are hoping for, at least. You need to understand the distinction between client and server as well as the concept of a request. MessageBox.Show does not work in ASP.NET due to the relationship between client and server. Resuming at a specific line of code does not work due to the nature of request/response. Yes, you can certainly show a dialog to the end user (via Javascript), but you won't have a way to resume at a specific line of code on the server. What you will have to do instead is to craft an endpoint within your application which can receive an additional request from the client once a button is pressed in your dialog. For this, you may want to look into AJAX, although you can achieve the same via normal postback (not quite as pretty as AJAX, but equally functional).
0

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
RadhaKrishnaKiJayaAuthor Commented:
Thank You very much.  Unfortunately I issue is not resolved yet.  But I have learned a lot from each of you.  Again, Thank You very much for your help.  I have no words for you guys.  That's why I asked the same question differently in the following string.  Please see if you can help.


http://www.experts-exchange.com/questions/28779159/Popup-message-with-Buttons-in-Java-Script-in-C-programming.html
0
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
JavaScript

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.