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
falsefrom the function if you don’t want the button push to go through in some cases. Currently you are only returning a value from the function when callingconfirm.If one or both of the if conditions fail, add a
return falseif you don’t want the event to bubble up activating the button/sending the form.Modification of your existing code
Is it still malfunctioning?
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.
In your definition of your button you have written
OnClientClick = "return childnode();", try changing this toOnClientClick="return childnode();"and see if that might solve the problem.See if the event fires at all,
OnClientClick="alert(123);".