We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

open confirmation in middle of button click event

lanac222
lanac222 asked
on
Medium Priority
253 Views
Last Modified: 2013-12-17
I see some people asked this question before. But I can not fully understand the solution or it was not solved at all.

Basically I have a button on C# web application page. Once user clicks the button it call some other function/process to get result. let's say the result is a string saved in a textbox on the page. Based on the string value 'yes' or 'No' to open confirmation or not, then catch the user's response from the confirmation to do rest stuff.

sample code:
==========================================
        protected void OverRide_Click(object sender, EventArgs e)
        {
            myResult.Text = "";
            myResult.Text = myFirstCheck(Customer.Text);
            if (Confirmation())
            {
                OverRideCustomer(Customer.Text, myResult.Text) ;
            }
            else
           {
               SendMessageToCust(Customer.Text)
           }
        }

==========================================================
Thnaks for help
Comment
Watch Question

if you can use ajax you can use the modalpopupextender.

just popup a panel with the result in it and a yes and no button. then you can handle the button click event for their choice


 protected void OverRide_Click(object sender, EventArgs e)
        {
            myResult.Text = "";
            myResult.Text = myFirstCheck(Customer.Text);
            modalpopupextender.Show();
        }
 
protected void ConfirmationYes_Click(object sender, EventArgs e)
        {
            OverRideCustomer(Customer.Text, myResult.Text) ;
        }
 
protected void ConfirmationNo_Click(object sender, EventArgs e)
        {
            SendMessageToCust(Customer.Text)
        }

Open in new window

You could do that with javascript.

if (document.getElementById("txtResponse").Value = "Yes")
{
   var answer = confirm("Are you sure?");
    if (answer) {
      return true;
    } else {
      return value;
}
Oops, that should be return false; in that else statement.

Author

Commented:
I fixed it by myself.
What did you do to fix it?  

Author

Commented:
OK, I still need help for this.

In cs code I set a value to a text field, say "OVERRIDE" and the script function for onload check the text field value. if it is OVERRIDE then call confirm. if return true then set another text field "YES", otherwise set "NO"
Following in the event to run process based on the 'yes' or 'no'.

My problem now is before exist the event the second text field is not set value. that mean the js function doesn't immediately execute.
How to make the js run immediately?
I was trying AJAX. But it doesn't work, it alway pop confirmation before do anything in the event.
Then I remove AJAX from the page.

=========================== cs code ===============
        protected void OverRide_Click(object sender, EventArgs e)
        {
            myResp.Text = "";
            ErrMessage.Text = "";
            // first call post with no override
            myRespL.Text = wInv.PostTankTemplate(strConnOC, txtInvDate.Text.Trim(),
                ddlBuilding.SelectedValue.Trim(), Session["login"].ToString().Trim(), "NO");
           //check return message for repost
            if (myResp.Text.Trim().Substring(myURL.Text.Trim().LastIndexOf("o"), 9) == "override?")
            {
                myParam.Text = "OVERRIDE";
                 ErrMessage.Text = wInv.PostTank(strConnOC, txtInvDate.Text.Trim(),
                    ddlBuilding.SelectedValue.Trim(), Session["login"].ToString().Trim(), myResp.Text.Trim());
            }
        }
======================================

========================= js =========================
<script>
      function CheckStatus()
      {
        if (document.MainForm.myParam.value == "OVERRIDE")
         {
             if (confirm(document.MainForm.myResp.value))
                   {
               document.MainForm.myParam.value="";
               document.MainForm.myResp.value="YES";
               }
               else
               {
               document.MainForm.myParam.value="";
               document.MainForm.myResp.value="NO";
               }
               
         }
    }  
    </script>
</head>
<body onload="CheckStatus()" onunload="CloseSubForms()">
    <form id="MainForm" method="post" runat="server">

Author

Commented:
I still need help.
Commented:
Yes, I'd like to open this question

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.