Popup message with Buttons in Java Script in C# programming

Hello Experts,
I am looking for Popup message box in a web page in C# programming.  Once Update Button is clicked, it needs to check the database for certain conditions.  If  found true, I need User Response message box with 2 Buttons (Continue and Cancel).  If Continue is clicked, it should continue with the Updates.  Otherwise it should Cancel the processing.  Please advise the best possible solution.  See the example below.  Thank you a lot in advance.

C# Code...
.
.
protected void btnUpdate_Click(object sender, EventArgs e)
{
      C# Code....
      .
      .
      if (condition == True)
      {
            Display Message Box (Continue and Cancel buttons)
            if (Continue is clicked)
            {
                  Continue processing...
            }
            else
            {
                   Skip 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.

Julian HansenCommented:
If you are using a framework like bootstrap it comes with modal dialog support.
Otherwise there are libraries out there that allow you to do this (sample here)

www.jqueryui.com has a dialog option (sample here)

You can roll your own using something like fancybox to do the popup http://fancybox.net/

Or you can create your own little popup library with a few lines of jquery and html see this sample or this one
0
RadhaKrishnaKiJayaAuthor Commented:
Thank you Julian Hansen,
The sample code you provided are not touching C# at all.  

- I need to call Javascript code from C# on condition  
- Again In Javascript, I need Yes and Cancel buttons
- If Yes is clicked, it will call C# method.  If Cancel is clicked, no need to do anything.

Please let me know if any confusion in my question.  Thank you again for your time.
0
Julian HansenCommented:
- I need to call Javascript code from C# on condition  
C# is server code JavaScript is client code - you can't call JavaScript from C#.
You can use C# to embed JavaScript in your rendered HTML - which is where the samples come in. You use C# to embed the JavaScript to open the popup.

No matter what you code in backend the front end is always going to be JavaScript and it is going to work on the principles outlined in the samples provided.
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.

RadhaKrishnaKiJayaAuthor Commented:
Is it possible for you to provide sample, but complete ABC.aspx, ABC.aspx.cs programs.  It is really hard to follow those samples.
0
Julian HansenCommented:
It is really hard to follow those samples.
Unfortunately that is the best I can do right now.
Google the following
c# .net popup window

You should find what you are looking for.
0
RadhaKrishnaKiJayaAuthor Commented:
Julian Hansen, Thank you for your time.  Here is the code, which is called from Code Behind to JS and Vice versa.  Thank you again!


CallJSFuncFromCSAndVV.aspx
------------------------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CallJSFuncFromCSAndVV.aspx.cs" Inherits="PopUpMessageBox.CallJSFuncFromCSAndVV" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    <script type = "text/javascript">

        function Confirm() {

            if (confirm("Do you want to save data?")) {
                $('#cmdYes').click();
                //YesClicked();
            }
            else {
                $('#cmdNo').click();
                //NoClicked();
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
   
         <h4>Call Confirm Message Box from code-behin in Asp.net</h4>
         <div>
             <asp:Button ID="btnConfirm" runat="server" Text = "Click Confirm"
                 onclick="btnConfirm_Click" />
             <asp:Button ID="cmdYes" runat="server" ClientIDMode="Static" style="display:none;" OnClick="cmdYes_Click" /><!--Hidden button  -->
             <asp:Button ID="cmdNo" runat="server" ClientIDMode="Static" style="display:none;" OnClick="cmdNo_Click" /><!--Hidden button  -->
         </div>
    </form>
</body>
</html>


CallJSFuncFromCSAndVV.aspx.cs
--------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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

      }

      protected void btnConfirm_Click(object sender, EventArgs e)
      {
          Call_JSConfirm();
      }

      protected void Call_JSConfirm()
      {
         ScriptManager.RegisterStartupScript(this, this.GetType(), "Confirm", "Confirm();", true);
      }

      protected void cmdYes_Click(object sender, EventArgs e)
      {
         int x = 10;
         string y = "Yes";
      }

      protected void cmdNo_Click(object sender, EventArgs e)
      {
         int x = 20;
         string n = "No";
      }
  }
}
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
Julian HansenCommented:
You are welcome.
0
RadhaKrishnaKiJayaAuthor Commented:
Already described.
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.