简体   繁体   English

删除不要求确认

[英]Delete does not ask for confirmation

When Delete button is clicked, the confirmation box should pop up if the selected node has child nodes. 单击“删除”按钮时,如果所选节点具有子节点,则将弹出确认框。 Otherwise, it should not do anything. 否则,它什么也不做。

Right now, when I click on delete, it just deletes without confirming. 现在,当我单击删除时,它只是删除而没有确认。

Here is the code: 这是代码:

  <asp:Button ID="btn_delete" runat="server" Height="32px" 
        onclick="btn_delete_Click"  OnClientClick = "return childnode();"                              
        Text="Delete" Visible="False"  />  

    <script type="text/javascript">
        function childnode() {
            var treeViewData = window["<%=nav_tree_items.ClientID%>" + "_Data"];

            var selectedNode = document.getElementById(treeViewData.selectedNodeID.value);
            if (selectedNode.childNodes.length > 0) {
                return confirm("heloo");
            }
            return false;
        }                                        
    </script>

You'll need to return false from the function if you don't want the button push to go through in some cases. 如果在某些情况下不希望按下按钮,则需要从函数返回false Currently you are only returning a value from the function when calling confirm . 当前,仅在调用confirm时从函数返回值。

If one or both of the if conditions fail, add a return false if you don't want the event to bubble up activating the button/sending the form. 如果一个或两个if条件均失败,则如果您不希望事件冒泡激活按钮/发送表单,则添加return false


Modification of your existing code 修改现有代码

function childnode() {
    var treeViewData = window["<%=nav_tree_items.ClientID%>" + "_Data"];
    if (treeViewData.selectedNodeID.value != "") {
        var selectedNode = document.getElementById(treeViewData.selectedNodeID.value);
        if (selectedNode.childNodes.length > 0) {
            return confirm("heloo");
        }   

        return false; // don't send form                                             
    }

    return false; // don't send form
}  

Is it still malfunctioning? 它仍然有故障吗?

  1. Make sure that the logic inside your function is accurate, webbrowsers will often fail silently when trying to get a property of an undefined variable. 确保函数内部的逻辑是正确的,当尝试获取未定义变量的属性时,网络浏览器通常会静默失败。

  2. In your definition of your button you have written OnClientClick = "return childnode();" 在按钮定义中,您编写了OnClientClick = "return childnode();" , try changing this to OnClientClick="return childnode();" ,请尝试将其更改为OnClientClick="return childnode();" and see if that might solve the problem. 看看是否可以解决问题。

  3. See if the event fires at all, OnClientClick="alert(123);" 查看事件是否完全触发, OnClientClick="alert(123);" .

Your function have return not in all of it's parts. 您的函数并没有全部return Probably your function exists without confirm. 可能您的功能存在而未确认。 Review your logic and decide what you want to do if one of your if statements not passed. 查看您的逻辑,并确定如果您的if语句之一未通过,您想做什么。

Change this: 更改此:

onclick="btn_delete_Click"  OnClientClick = "return childnode();"

To this: 对此:

onclick="btn_delete_Click;return childnode();"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM