locked
Update Panel Alert Comfirm Message RRS feed

  • Question

  • User197255166 posted

    Hello everyone,

    I want to do alert comfirm message . How can I do if click Yes go on process but if click the cancel return process. Can you help me?

      string message = "Yeterli puanınız yok. Dilerseniz Kredi Kartı ile alabilirsiniz.";
                        System.Text.StringBuilder sb = new System.Text.StringBuilder();
                        sb.Append("return confirm('");
                        sb.Append(message);
                        sb.Append("');");
    
                        
                        ScriptManager.RegisterStartupScript(this, typeof(string), "Message", "if(confirm('Yeterli puanınız yok. Dilerseniz Kredi Kartı ile alabilirsiniz.')){alert('Yes');}else{alert('cancel');}", true);
                      

    Wednesday, August 3, 2016 1:51 PM

Answers

  • User197255166 posted

    I did your example, At the same time I am using Update Panel. I dont add button click CustomMessage. Because  only I need button click.

     <script>
          function CustomMessageBox(msg) {
              //Hidden Control to hold the value selected by user
              var confirm_value = document.createElement("INPUT");
              confirm_value.type = "hidden";
              confirm_value.name = "confirm_value";
              //Show the confirm Message
              if (confirm(msg)) {
                  //Set the hidden field value as Yes
                  confirm_value.value = "Yes";
              } else {
                  //Set the hidden field value as No
                  confirm_value.value = "No";
              }
              document.forms[0].appendChild(confirm_value);
          }
            </script>

    Code Behind.

     string confirmValue = Request.Form["confirm_value"];
                        if (confirmValue == "Yes")
                        {
                            //Your code if user selected Yes in message box
                        }
                        else
                        {
                            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked NO!')", true);
    
                        }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 3, 2016 3:08 PM

All replies

  • User2103319870 posted

    How can I do if click Yes go on process but if click the cancel return process. Can you help me?

    You can try with the below implementation

     <script>
                function CustomMessageBox(msg) {
                    //Hidden Control to hold the value selected by user
                    var confirm_value = document.createElement("INPUT");
                    confirm_value.type = "hidden";
                    confirm_value.name = "confirm_value";
                    //Show the confirm Message
                    if (confirm(msg)) {
                        //Set the hidden field value as Yes
                        confirm_value.value = "Yes";
                    } else {
                        //Set the hidden field value as No
                        confirm_value.value = "No";
                    }
                    document.forms[0].appendChild(confirm_value);
                }
            </script>
    
    
            <asp:Button ID="btnConfirm" runat="server" Text="Confirm" OnClientClick="CustomMessageBox('Yeterli puanınız yok. Dilerseniz Kredi Kartı ile alabilirsiniz.')" OnClick="btnConfirm_Click" />

    C#:

    protected void btnConfirm_Click(object sender, EventArgs e)
            {
                //Get the hidden value
                string confirmValue = Request.Form["confirm_value"];
                if (confirmValue == "Yes")
                {
                    //Your code if user selected Yes in message box
                }
                else
                {
                    this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked NO!')", true);
                }
            }

    Source url

    Wednesday, August 3, 2016 2:03 PM
  • User197255166 posted

    Sorry I dont want button click. I want to do button code behind according to condition. Below I did but How can I do if click No I want to be return. İf click yes I want to be go on process.

     System.Text.StringBuilder sb = new System.Text.StringBuilder();
                        sb.Append("<script type = 'text/javascript'>");
                        sb.Append("window.onload=function(){");
                        sb.Append("confirm('");
                        sb.Append("Hi");
                        sb.Append("')};");
                        sb.Append("</script>");
                        ClientScript.RegisterClientScriptBlock(this.GetType(), "confirm", sb.ToString());
    
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "confirm('Would you like to be put on the wait list?')", true);

    Wednesday, August 3, 2016 2:09 PM
  • User2103319870 posted

    orry I dont want button click.

    Button click I added for a demo purpose. You can use the set of code inside button click in the place you are trying to open alert popup

    Wednesday, August 3, 2016 2:58 PM
  • User197255166 posted

    I did your example, At the same time I am using Update Panel. I dont add button click CustomMessage. Because  only I need button click.

     <script>
          function CustomMessageBox(msg) {
              //Hidden Control to hold the value selected by user
              var confirm_value = document.createElement("INPUT");
              confirm_value.type = "hidden";
              confirm_value.name = "confirm_value";
              //Show the confirm Message
              if (confirm(msg)) {
                  //Set the hidden field value as Yes
                  confirm_value.value = "Yes";
              } else {
                  //Set the hidden field value as No
                  confirm_value.value = "No";
              }
              document.forms[0].appendChild(confirm_value);
          }
            </script>

    Code Behind.

     string confirmValue = Request.Form["confirm_value"];
                        if (confirmValue == "Yes")
                        {
                            //Your code if user selected Yes in message box
                        }
                        else
                        {
                            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked NO!')", true);
    
                        }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 3, 2016 3:08 PM
  • User61956409 posted

    Hi Aliyilmaz,

    According to your code, it seems that you store the value that confirm() method returns in form input, and then you retrieve the value from Request.Form collection from code behind. Thanks for sharing your solution.

    Best Regards,

    Fei Han

    Friday, August 5, 2016 9:52 AM