Welcome Guest Search | Active Topics | Sign In | Register

Declaring ItemMoved Event in codebehind Options
sacredspirita
Posted: Friday, September 14, 2007 6:14:49 AM
Rank: Newbie
Groups: Member

Joined: 9/12/2007
Posts: 6
I am sure I am probably missing something... but I am trying to capture on that event.

I put a basic function in and put a break point on the addition.

private void eoTreeView_ItemMoved(object sender, EO.Web.TreeNodeMovedEventHandler e)
{
int i = 0;
i = i + 2; <-----break point for debugger
}

However, when I run my ap and move a node to be somewhere else. This event is never fired and I never go to the break point.

SGML Declaration
<eo:TreeView ID="eoTreeView" runat="server" Height="250px" Width="200px" AllowDragDrop =true></eo:TreeView>

Page_load binds it to a table.

Could you tell me what I am missing?

Many Thanks,

Angela
eo_support
Posted: Friday, September 14, 2007 6:56:19 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,089
Hi Angela,

ItemMoved is a "delayed" event. It's similar to TextBox.TextChanged event, it does not get called immediately until the page postbacks. If you put a button in the page, move the node, then click the button, you will see the event being fired.

Thanks
sacredspirita
Posted: Friday, September 14, 2007 9:39:53 AM
Rank: Newbie
Groups: Member

Joined: 9/12/2007
Posts: 6
Hi Again,

Thanks for the information :)

Can you tell me or point me to how I can get it to automatically post back after the change. I am getting confused still...My .NET is limited to junior level. When the cange happens I want to automatically save it to the database.

I tried doing this thinking it should post back...

<eo:TreeView ID="eoTreeView" runat="server" Height="250px" Width="200px" AllowDragDrop =true ClientSideOnDragOver="eoTreeView_Save">

to a codebehind function I declared.

protected void eoTreeView_Save(object sender, EventArgs e)
{
int i = 0;
i = i + 2;<----break point
}

but that is not working either...

If I put ClientSideOnDragOver="alert('hi there')" that doesn't work either...

Any help is appreciated...

Angela
eo_support
Posted: Friday, September 14, 2007 10:46:22 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,089
Hi,

I believe there is a problem with ClientSideOnDragOver in the current build. I've sent you a private message with download location for a new build that should work properly.

ClientSideOnDragOver takes a client side function name. So neither "eoTreeView_Save" (a server side handler) nor "alert('hi there')" (a statement rather than a function name) would work. Also, you definitely do not want to handle ClientSideOnDragOver, because ClientSideOnDragOver can occurs many times while you are dragging the node, the correct event you want to handle is ClientSideOnDragDrop.

Once you get the new build, try the following code and it should get you going:

Code: JavaScript
function TreeView_OnDragDrop(treeView, srcNode, destNode)
{
    window.setTimeout("__doPostBack('LinkButton1', '');", 10);
}


Code: HTML/ASPX
<eo:TreeView ClientSideOnDragDrop="TreeView_OnDragDrop" ...>
....
</eo:TreeView>


The TreeView_OnDragDrop handler use a timer to trigger __doPostBack, which triggers a post back. Using a timer is important to let the TreeView to finish its normal flow.

The first parameter of __doPostBack is the ID of the control that triggers the event. So in the sample code shown above, if you do have a LinkButton1 in your page, that button's Click event will also get triggered.

Thanks
Eric T
Posted: Wednesday, September 19, 2007 11:45:27 AM
Rank: Member
Groups: Member

Joined: 6/5/2007
Posts: 15
First, I'm working on a TreeView with drag & drop, so if you could also PM me a link to the build, that's appreciated.

Second, is there a way to have the Nodes with a NavigateURL and also have drag & drop functionality? If someone does a normal mouse click, I'd like them to go on the NavigateURL, but if they are D&D, I'd like it to just drop without going to NavigateURL. Currently, as soon as the user "drops", it immediately goes to the page specified in NavigateURL without even calling ItemMoved server-side.

Basically, I'd like to cancel the page change OnDrop. Any ideas or help? The workaround is to have the users go into D&D mode and disable all of the NavigateURLs, but I was hoping to accomplish this without having to take that step.
eo_support
Posted: Wednesday, September 19, 2007 12:05:29 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,089
Hi Eric,

I've PMed you the link to the build.

Having D&D and NavigateUrl to work at the same time is tricky business. Just as you have observed, a click is fired right after you drop the node. In order to avoid this, you would want to do the navigation by yourself. Here is a brief summary of the steps:

1. Instead of putting the target Url into NavigateUrl, put them into Value property;
2. Handle both ClientSideOnDragDrop and ClientSideOnItemClick;
3. Inside ClientSideOnDragDrop, remember the dropped node and the time that it was dropped;
4. Inside ClientSideOnItemClick, check whether the clicked node has been just been dropped (for example, within 100ms), if so return directly, otherwise call window.open(node.getValue());

Let us know if that works for you.

Thanks
sacredspirita
Posted: Wednesday, September 19, 2007 12:48:58 PM
Rank: Newbie
Groups: Member

Joined: 9/12/2007
Posts: 6
Hi there,

Sorry this took me a while to get too...

I downloaded the new version and installed it in my test area....

I would prefer not doing javascript timeouts in order to get automatic post backs. My experience with 3rd party tools doing that has not been the best. I will use it as a last resort but I am not there yet.

So, I went back to the ItemMoved event to see how I could design a screen and be able to save menu changes.

However, ItemMoved is still not getting fired on form submittal.

Declaration in MASTER file

Code:

<tr>
                        <td>
                            <eo:TreeView ID="eoTreeView" runat="server" Height="250px" Width="200px" AllowDragDrop =true
                             >
                            </eo:TreeView>
                        </td>
                    </tr>
                    </tr>
                    <tr>
                        <td>
                            <asp:Button runat="server" ID="btnSave" Text="Save" OnClick="btnSave_Click" />
                        </td>
                    </tr>



Declaration in codebind

Code:

   protected void eoTreeView_ItemMoved(object sender, EO.Web.TreeNodeMovedEventHandler e)
    {
        int i = 0;
        i = i + 2; <---break point set BUT does NOT ever Break on this part of code
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        int i = 0;
        i = i + 2; <---break point set and DOES actually break there.
    }


So basically, the break point I set in the Click event executes and stops the code. However, the break point that is set for ItemMoved never gets executed.

I will tell you right now that this test code is taking place in a MASTER file for .NET I don't know if that makes a difference with your control.

So, writing that I did a quick test with the above code in a normal ASPX file, and I still get the same results. ItemMoved not firing when a drag/drop occurs.


Any help again is truly appreciated,

Angela

eo_support
Posted: Wednesday, September 19, 2007 1:02:02 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,089
Hi,

I am not sure if MASTER file has anything to do with it. Just a dumb question, I noticed that you have OnClick="btnSave_Click" to hook up btnSave_Click with the button, but I do not notice anything to hook up eoTreeView_ItemMoved to your TreeView. Are you sure the event handler is hooked up correctly?

Thanks
Eric T
Posted: Wednesday, September 19, 2007 1:02:24 PM
Rank: Member
Groups: Member

Joined: 6/5/2007
Posts: 15
OK, I will try that. I have another issue with D&D, specifically on the ItemMoved event. Since this is delayed until postback and there is no autopostback, the users can move multiple items. The ItemMoved is called multiple times, but the Index is wrong when 2 or more are moved around -- some nodes are returned that were not moved.

Code: Visual Basic.NET
Protected Sub TreeView1_ItemMoved(ByVal parObj As Object, ByVal parArgs As EO.Web.TreeNodeMovedEventArgs) Handles TreeView1.ItemMoved
        Response.Write(parArgs.Node.Text & ": " & parArgs.Node.Index)
    End Sub


For example, in a 5 item list, moving an element from index=3 to index=1 and then index=4 to index=0, the ItemMoved returned Node.Index 4 and 1. I can't figure out what these Index values should be when 2 or more items are moved.

I have two more questions that have not been readily obvious in your documentation that I hope you can help with.

1) How can you have a different Context Menu for Top Folders/Nodes (level=0, has subnodes), Sub Folders/Nodes (level = 1+) and Leaf Nodes? ContextMenu is bound to the TreeView and not to the various levels, and it's a client-side script.

2) Can you just have reordering of nodes without ability to create subnodes? I really just want the "black line" reorder where items switch places and not the kind where you can make a node a child of another. Based on your documentation, I think you can have the kind that creates child nodes without reorder, but can't have reorder without child node turned on?

Thanks,
Eric
Eric T
Posted: Wednesday, September 19, 2007 1:05:49 PM
Rank: Member
Groups: Member

Joined: 6/5/2007
Posts: 15
PS, sorry for jumping in on this topic, Angela. You were the closest that I found in a forum search!
eo_support
Posted: Wednesday, September 19, 2007 1:14:08 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,089
Hi,

ItemMoved is called for each move, which means if you moved the same node twice, ItemMoved will be called twice with the same node. If you moved two different nodes, ItemMove will be called twice with those two nodes. So it does not matter how many times user has moved the node. ItemMoved should always give you the index as reflected by a specific move.

As for context menu, you never associate a context menu to the TreeView. You implement context menu by handling ClientSideOnContextMenu and do whatever you like ---- even displaying a message box instead of a context menu:

http://www.essentialobjects.com/Demo/Default.aspx?path=TreeView\_i1\_i9

In order to reordering of nodes without ability to create subnodes, you will need to handle CllientSideOnDragBegin and ClientSideOnDragOver. You will return false from ClientSideOnDragOver to refuse the drop if you see the node below the dragging node not suitable to be a drop target.

Thanks
Eric T
Posted: Wednesday, September 19, 2007 1:22:36 PM
Rank: Member
Groups: Member

Joined: 6/5/2007
Posts: 15
I understand that it's called for each move, my problem is that the Index and Node returned on 2 or more moves are not correct. I am getting Nodes returned that were not moved/touched via drag & drop.

On the context menu, this still does not answer how I can query client-side whether the user is context-clicking on a top-level node, leaf node or subnode. Server-side, you have properties for those. In our implementation, we need different options available in the context menu based on Top Level, Leaf or Subgroup. I can handle the options if I can tell info on the node clicked on the client.

OK on the cancelling of ClientSideOnDragOver, that's what I needed to know.
eo_support
Posted: Wednesday, September 19, 2007 1:41:55 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,089
Hi Eric,

For the node move, it might because you didn't realize moving one node not only causing the node itself's Index to change, but also a bunch of other node's Index to change. And the Index is only valid when ItemMoved is called. For example, when the first node is moved to the second place and then moved to the third pace, during the first ItemMoved event you will see the original third item's Index as 2 (unchanged), but you will see it's Index as 1 during the second ItemMoved event. If you are still unsure about how this works, you can create a static one level TreeView with 3 or four items and place with it, you will see how it works.

ClientSideOnContextMenu handler passes you the node that is right-clicked. So there is no issue there.

Thanks
Eric T
Posted: Wednesday, September 19, 2007 1:52:23 PM
Rank: Member
Groups: Member

Joined: 6/5/2007
Posts: 15
It passes the node, but the client-side only exposes isLeafNode method. There is no isTopLevel method like there is a server-side property. Please advise if there is a different way to tell client-side if a node is Top Level.
eo_support
Posted: Wednesday, September 19, 2007 1:58:03 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,089
Use getLevel(). TreeNode inherits from NavigationItem. So it has a whole bunch of methods there.
Eric T
Posted: Wednesday, September 19, 2007 2:00:12 PM
Rank: Member
Groups: Member

Joined: 6/5/2007
Posts: 15
Ah, I missed that it inherited it. I was just looking at the tree list of items in the Content section of the Help file and only saw 7 things under TreeNode client API.

Thank you for all of the answers today!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.