execute different codes in code behind on confirm

2019-09-03 03:05发布

问题:

I want to have a confirm message on text_changed event and execute different set of codes on ok and cancel. Help me with these codes

<script type = "text/javascript">
     function Confirm() {
         var confirm_value = document.createElement("INPUT");
         confirm_value.type = "hidden";
         confirm_value.name = "confirm_value";
         if (confirm("Do you want to save data?")) {
             confirm_value.value = "Yes";
         } else {
             confirm_value.value = "No";
         }
         document.forms[0].appendChild(confirm_value);
     }
    </script>

 <asp:TextBox ID="TextBox1" runat="server"  ontextchanged="TextBox1_TextChanged"></asp:TextBox>

Code Behind

protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
       // TextBox1.Attributes.Add("OnClientClick", "Confirm()");
        string confirmValue = Request.Form["confirm_value"];
        if (confirmValue == "Yes")
        {
            //Your logic for OK button
        }
        else
        {
            //Your logic for cancel button
        }
    }
 public void OnConfirm(object sender, EventArgs e)
    {
    }

It is done like this, But I want to do it without using button, I want to use textbox only

回答1:

You can find answer from following link.

https://stackoverflow.com/a/20117247/1381667

It seems that you post same question 2 times, It is perfectly ok but try to edit your question if you think it is not express your problem perfectly instead of posting new one.