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

OnContextMenuItemClick not fired when using Custom RadTreenNodes

2 Answers 105 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Kasper Lindgaard
Top achievements
Rank 1
Kasper Lindgaard asked on 22 Oct 2010, 11:40 AM
So I have been working with RadTreeView and it's context menu with succes, to test if it could solve a problem of mine. Next problem  was that the RadTreeNodes could not contain enough information, so I created my own TreeNodes, and extended those to RadTreeNode. I could create and add the new Nodes to the RadTreeNode without any problems.

But when I tested my treeview, it's showed all nodes i added. When i rightclick the contextmenu pops up, but when clicking on any menuitem, the OnContextMenuItemClick event is not fired. I tried remove all of my nodes, and only add one original RadTreeNode. This works.

I found out that the problem also affects OnNodeDrop and OnNodeEdit events.

It sounds like using costum nodes corrupts some event system. Is this true?

Here are my code snippets:

Custom node:
public class ReportTreeNode : RadTreeNode
    {
        public ReportTreeNode(String text) : base(text)
        {
            Locked = false;
        }
 
        public ReportTreeNode(String text, String value) : base(text, value)
        {
            Locked = false;
        }
 
        public ReportTreeNode(String text, String value, String image)
            : base(text, value)
        {
            Locked = false;
            ImageUrl = image;
        }
 
        public ReportTreeNode(String text, String value, String image, String type)
            : base(text, value)
        {
            NodeType = type;
            Locked = false;
            ImageUrl = image;
        }
 
        public bool Locked { get; set;}
 
        /// <summary>
        /// The report node type. eg. Section, textarea, pagebreak etc.
        /// </summary>
        public String NodeType { get; set; }
 
        /// <summary>
        /// Returns the depth location of the node
        /// </summary>
        /// <returns></returns>
        public int getDepthOfNode()
        {
            int result = 0;
            foreach (char c in FullPath)
            {
                if (c == '/')
                    result++;
            }
            return result;
        }
    }


TreeView:
<telerik:RadScriptManager ID="scriptmanager" runat="server" />
        <telerik:RadAjaxLoadingPanel  ID="RadAjaxLoadingPanel1" runat="server" ><img src="anidog2.gif" /></telerik:RadAjaxLoadingPanel>
        <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1">
            <asp:Literal ID="statusMessage" runat="server"></asp:Literal><br />
            <telerik:RadTreeView ID="template" runat="server" EnableDragAndDrop="true" EnableDragAndDropBetweenNodes="true"
            OnContextMenuItemClick="dynamicMenu_ContextMenuItemClick" OnNodeDrop="dynamicMenu_OnNodeDrop" OnNodeEdit="dynamicMenu_OnNodeEdit" AllowNodeEditing="true" OnLoad="templateOnInit">
                <ContextMenus>
                    <telerik:RadTreeViewContextMenu>
                        <Items>
                            <telerik:RadMenuItem Text="Add" Value="none" ImageUrl="application_add.png">
                                <Items>
                                    <telerik:RadMenuItem Text="Section" Value="add:section" ImageUrl="section.png"/>
                                    <telerik:RadMenuItem Text="Textarea" Value="add:textarea" ImageUrl="testArea.png"/>
                                </Items>
                            </telerik:RadMenuItem>
                            <telerik:RadMenuItem Text="Add Custom Section" Value="addCustom" ImageUrl="application_add.png" runat="server" />
                            <telerik:RadMenuItem Text="Delete" Value="delete" ImageUrl="application_delete.png" runat="server" />
                        </Items>
                    </telerik:RadTreeViewContextMenu>
                </ContextMenus>
            </telerik:RadTreeView>
        </telerik:RadAjaxPanel>



And here I add a node to the treeview:
protected void templateOnInit(object sender, EventArgs e)
        {
            if(IsPostBack)
                return;
            template.Nodes.Clear();
 
            ReportTreeNode report = new ReportTreeNode("Report", "report", picturepath + "/report.png", "report");
            report.Locked = true;
            template.Nodes.Add(report);
            return;
        }

if anyone have an answer to this, I would be happy.

2 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay Tsenkov
Telerik team
answered on 27 Oct 2010, 11:18 AM
Hi Kasper Lindgaard,

The problem here is that you don't have an empty constructor for your implementation of ReportTreeNode and this is required for the recreation of the nodes on the server before the viewstate is applied. You simply need to add this constructor to the already implemented class and it should be fine:
public ReportTreeNode()
    :base()
{
         
}

You didn't received any sign of the exception thrown, because it was in ajax response.

Hope this solves problem!


Regards,
Nikolay Tsenkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Kasper Lindgaard
Top achievements
Rank 1
answered on 27 Oct 2010, 01:32 PM
PERFECT!

Now it works brilliantly. Thank you very much.
Tags
TreeView
Asked by
Kasper Lindgaard
Top achievements
Rank 1
Answers by
Nikolay Tsenkov
Telerik team
Kasper Lindgaard
Top achievements
Rank 1
Share this question
or