execute different codes in code behind on confirm ok and cancel

亡梦爱人 提交于 2019-12-13 04:53:03

问题


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.



来源:https://stackoverflow.com/questions/20112536/execute-different-codes-in-code-behind-on-confirm-ok-and-cancel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!