Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
25
Set Behavioral Property with JavaScript or Cancel Drop Event
posted

Hi,

I have a tree that has Drag & Drop enabled by default, but I want to the user to be able to toggle this functionality on and off without having to postback.  I've worked with Infragistics controls for a while now, but have pretty much always used server-side code to manipulate the controls.  I have been studying JavaScript lately as a way to improve site performance, so this aspect is new to me and I'm having a problem, and no one else on the team here knows anything about JavaScript.

The documentation found for WebTree CSOM at http://help.infragistics.com/NetAdvantage/ASPNET/2009.2/CLR3.5/ indicates that I should be able to access tree properties such as AllowDrop client-side, but I am unable to find this property in the CSOM.

I have added an "onClick" attribute to a separate control which calls a function intended to toggle the behavior.  I am passing the ClientID value, which is "ctl00_ContentPlaceHolder1_wdtAllAssetsTree" because I'm using a MasterPage, to the JS function.

    function toggleDragDrop(tree) {
        var tree = document.getElementById(tree.id);
    }

When I examine this variable named tree in debug mode, it has a property named ID with a value of "ctl00_ContentPlaceHolder1_wdtAllAssetsTree" and a collection of attributes with names like "onbeforeactivate" or "aria-hidden" but I cannot find the properties that I am used to being able to set server-side, such as AllowDrag, AllowDrop, SkinID, Width, etc.

An acceptable alternate solution, which was what I tried first but couldn't get to work, is a way to intercept the drop event, display a confirmation to the user to make sure they wanted to drag & drop the node, and then cancel the event if they clicked no (otherwise continue the drop event and postback).  I could only get the confirm prompt to show up in the DragStart event which was not helpful.

For example, I had tried to use this function as a starting point, but it doesn't work properly (it executes twice, and doesn't cancel the event)

    function onDrop(oTree, oNode, oDataTransfer, oEvent) {
        if (!confirm('Do you really want to move this node?')) {
            alert('canceling drop');
            return true;
        }
    }

What I am looking for is either how to get and set the "AllowDrop" property of the tree from the client-side code, or how to stop the drag & drop from following through if the user cancels a confirmation dialog.  I get the feeling I'm just missing something simple.  Any help would be appreciated.  Thanks!

Parents
No Data
Reply
  • 3726
    Verified Answer
    posted

    Hi,

    take a look at samples.infragistics.com -> ASP.NET -> WebDataTree -> Drag & Drop

    There are plenty of samples with code that you can take a look how to subscribe for an event and cancel it. Drag & Drop can not be disabled on the client side once enabled on the server side. In order to stop a drag you can subscribe to dragStart event and cancel it. Then the user will not be able to drag anything. When you think it is suitable to allow drags, you can modify your code in the dragStart event.

    Look at the online samples code.

    Thanks,

    Lubomir

Children