Welcome Guest Search | Active Topics | Sign In | Register

ContextMenu and Treeview... Options
James
Posted: Wednesday, February 13, 2008 5:11:35 PM
Rank: Newbie
Groups: Member

Joined: 2/13/2008
Posts: 5
I am evaluating the EO web objects for use in a project that we are working on. Specifically I am looking at the treeview and contextmenu controls.

When the ItemClick event for the contextmenu is triggered the TreeNode parameter in the e EventArgs is empty. Does anyone know why?

The code uses a custom class collection (inherits from ArrayList) and binds that to the TreeView. I have set the ContextControlID of the COnextMenu to the TreeView control. The ContextMenu pops up on the TreeView as it is supposed to. Howeve as I mentioned above, the TreeNode parameter in the ItemClick event is empty.


I am likely missing something obvious, so any help is much appreciated.

eo_support
Posted: Wednesday, February 13, 2008 5:30:38 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,083
Hi James,

TreeNode parameter in the e EventArgs is valid only when the event source is a TreeView, in the case of a ContextMenu from the TreeView, the event source is still the ContextMenu, not the TreeView, so you won't have that from the event args.

Also, the TreeView has built-in context menu support via ClientSideOnContextMenu property:

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

ClientSideOnContextMenu is a client side event, so you would give it a JavaScript function name. When user right click on a tree node, that function will be called and the node that was clicked will be passed to your handler. You can take a look of the source code of that sample to see how it works.

Since ClientSideOnContextMenu is on the client side, so if you need to pass the clicked node to the server side, you can pass it through a hidden field. For example:

Code: HTML/ASPX
<input type="hidden" id="rightClickedTreeNodePath" />


Code: JavaScript
function Your_ClientSideOnContextMenu_Handler(e, treeView, node) 
{
    var field = document.getElementById("rightClickedTreeNodePath");

    //Save the clicked node's Path in rightClickedTreeNodePath. 
    //This value can later be retrieved by 
    //"Request.Form["rightClickedTreeNodePath"]" on the server 
    //side
    field.value = node.getPath();

    eo_ShowContextMenu(e, "ContextMenu1");
}


By the time you are inside ItemClick event for the context menu on the server side, you can use the following code to get the corresponding TreeNode:

Code: C#
//Get the node path
string path = Request.Form["rightClickedTreeNodePath"];

//Get the node from the path
EO.Web.TreeNode node = TreeView1.FindItem(path);


That should get you going. Please let us know if you need more help.

Thanks

James
Posted: Wednesday, February 13, 2008 5:54:02 PM
Rank: Newbie
Groups: Member

Joined: 2/13/2008
Posts: 5
Thank you! That worked perfectly. It was exaclty what I was looking for.

So far, I'm glad I found these EO controls and look forward to purchasing them.
eo_support
Posted: Wednesday, February 13, 2008 6:31:43 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,083
Excellent! Please feel free to let us know if you have any other questions.


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.