This is a migrated thread and some comments may be shown as answers.

Dynamic Context menus

7 Answers 126 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Rishi
Top achievements
Rank 1
Rishi asked on 09 Mar 2010, 07:34 PM
Hi

Is there a way to create and attach context menus to the items on the tree based on the level they are on after the data is bound to the tree??
Would it be any different if it were a load on demand tree.?
Because I would have or not have different context menus on different nodes depending on their level.

Thanks

7 Answers, 1 is accepted

Sort by
0
Accepted
Schlurk
Top achievements
Rank 2
answered on 09 Mar 2010, 10:21 PM
You should be able to see an example of how to do this in this demo :)
0
Thomas
Top achievements
Rank 1
answered on 18 Apr 2011, 05:33 PM
The posted solution works fine in cases where you can load the permissions or lets say the "context menu items that should be shown on a specific item" are know at the time when you create the treeviewitem. Is there any solution to load this information on demand. So, for example:
A tree with some item A, B  and C.
A context menu with the items "Add" and "Delete"
When the user requests the context menu for item A we have to ask the server if the user is allowed to add/delete.

I can't do a postback, otherwise the context menu disappears again. I can't use any async webservice-call either.
Any suggestions how I could solve this?

Thanks in advance,
Thomas
0
Nikolay Tsenkov
Telerik team
answered on 21 Apr 2011, 05:49 PM
Hi Thomas,

If the context that you need to request is the user permissions, then you can create the context menu server side with regard to this factor. Could you, please, share what seems to be the problem implementing it this way?


Regards,
Nikolay Tsenkov
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Thomas
Top achievements
Rank 1
answered on 26 Apr 2011, 08:30 AM
The problem is that:
1. The user permissions are item-specific. A user might have the right to rename and delete "tree item A", but does not have the permission to delete "tree item B"
2. The tree is large and loading the permission for one tree item does take very long. So loading the permissions for all items when the tree is created is infeasible.

Therefore we want to load the permissions for a tree item from the server when the user right-clicks a tree item and before the menu is shown.
OnClientContextMenuShowing seemed perfect, but doesn't really work out, as mentioned before. A server-side event OnContextMenuShowing would solve the problem, but doesn't exist.
Any workarounds?

Regards,
Thomas

0
Helen
Telerik team
answered on 29 Apr 2011, 11:55 AM
Hello Thomas,

Please find attached a sample how to achieve this with RadAjaxManager.

Hope it helps.

Greetings,
Helen
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Thomas
Top achievements
Rank 1
answered on 02 May 2011, 12:27 PM
Hello,

Thank you very much for your effort. But unfortunately, this solution has a problem:

You show the menu with the client script:
var menu = $find("<%= Menu1.ClientID %>");
menu.showAt(menuX, menuY);

The menu shows up, but none of the click-events of the context menu items (OnClientContextMenuItemClicking, OnClientContextMenuItemClicked, OnContextMenuItemClick,...) works anymore. 

To verify this... in your example solution add the to client events to the RadTreeView-Tag:
OnClientContextMenuItemClicking="MenuItemClicking" OnClientContextMenuItemClicked="MenuItemClicked"
and some event handlers like this:
function MenuItemClicking(sender, args) {
    alert("menu item clicking");
}
function MenuItemClicked(sender, args) {
    alert("menu item clicked");
 }

Nothing happens when you click on a menu item (no matter if it's enabled or not)

Is there any way to fix this?
0
Helen
Telerik team
answered on 03 May 2011, 01:46 PM
Hi Thomas,

Please modify the "OnAjaxResponseEnd"  javascript function like the following:

function OnAjaxResponseEnd(sender, args) 
{
    if (args.EventArgument == nodeText) {
    var menu = $find("<%= Menu1.ClientID %>");
    var tree = $find("<%= RadTreeView1.ClientID %>");
     
    menu.showAt(menuX, menuY);
    menu.add_itemClicking(MenuItemClicking);
    menu.add_itemClicking(MenuItemClicked);
    }                     
}

Hope it helps.

Kind regards,
Helen
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
TreeView
Asked by
Rishi
Top achievements
Rank 1
Answers by
Schlurk
Top achievements
Rank 2
Thomas
Top achievements
Rank 1
Nikolay Tsenkov
Telerik team
Helen
Telerik team
Share this question
or