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

Dynamic ContextMenu not working

1 Answer 80 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Lukas
Top achievements
Rank 2
Lukas asked on 07 Jun 2010, 01:39 PM
Hi,

I have a RadTreeView with dynamic items, dynamically added on server-side. The RadTreeView has 2 ContextMenues declared in HTML, on server-side I set the ContextMenueID-Property depending on an attribute from the database (simplified in the example)

If I run the site, I get a Javascript error "menu is null" on line "var items = menu.get_items();"

This used to work before, but I don't know version I used back then.
Now I'm using newest release 2010.1.519(.40)

Here's the aspx-Content:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="test.aspx.vb" Inherits="Intranet.test" %> 
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head id="Head1" runat="server"
    <title>Intranet</title> 
</head> 
 
<body style=" background-color:White;"
    <form id="form1" method="post" runat="server"
    <telerik:RadScriptManager ID="RadScriptManager2" runat="server"
    </telerik:RadScriptManager> 
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"
        </telerik:RadAjaxManager> 
 
        <div class="divMenue">  
            <telerik:RadAjaxPanel ID="rap_Menue" runat="server" ClientIDMode="Static"
                <telerik:RadTreeView ID="rtv_Menue" ClientIDMode="Static" Runat="server" DataNavigateUrlField="URL" 
                    DataTextField="Title" EnableViewState="true" 
                    AfterClientToggle="AfterClientToggle" EnableDragAndDrop="True"                          
                    EnableDragAndDropBetweenNodes="True" LoadingMessage="Wird geladen ..." OnClientContextMenuShowing="ClientContextMenuShowing"               
                    Skin="Default" OnClientLoad="setTree" > 
                    <ContextMenus> 
                        <telerik:RadTreeViewContextMenu ID="ctm_FavMenu" runat="server"  
                Skin="Default">                         
                            <Items> 
                                <telerik:RadMenuItem runat="server" Text="New"
                                    <Items> 
                                        <telerik:RadMenuItem> 
                                            <ItemTemplate> 
                                                <table> 
                                                    <tr> 
                                                        <td>Name:</td> 
                                                        <td><asp:TextBox runat="server" ID="txt_FavName" Width="300px" /></td
                                                    </tr> 
                                                    <tr> 
                                                        <td>URL</td> 
                                                        <td><asp:TextBox runat="server" ID="txt_FavURL" Width="300px" /></td
                                                    </tr>                 
                                                    <tr> 
                                                        <td>Icon</td> 
                                                        <td> 
                                                            <asp:RadioButtonList runat="server" RepeatColumns="8" ID="rbl_FavIcon" /> 
                                                        </td> 
                                                    </tr>                                                 
                                                </table>                 
                                            </ItemTemplate> 
                                        </telerik:RadMenuItem> 
                                        <telerik:RadMenuItem runat="server" IsSeparator="true"/> 
                                        <telerik:RadMenuItem runat="server" Text="Speichern"/> 
                                    </Items> 
                                </telerik:RadMenuItem> 
                                <telerik:RadMenuItem runat="server" Text="Edit"
                                    <Items> 
                                        <telerik:RadMenuItem> 
                                            <ItemTemplate> 
                                                <table> 
                                                    <tr> 
                                                        <td>Name:</td> 
                                                        <td><asp:TextBox runat="server" ID="txt_FavNamechng" Width="300px" /></td
                                                    </tr> 
                                                    <tr> 
                                                        <td>URL</td> 
                                                        <td><asp:TextBox runat="server" ID="txt_FavURLchng" Width="300px" /></td
                                                    </tr>                 
                                                    <tr> 
                                                        <td>Icon</td> 
                                                        <td> 
                                                            <asp:RadioButtonList runat="server" RepeatColumns="8" ID="rbl_FavIconchng" /> 
                                                        </td> 
                                                    </tr>                                                 
                                                </table>                 
                                            </ItemTemplate> 
                                        </telerik:RadMenuItem> 
                                        <telerik:RadMenuItem runat="server" IsSeparator="true"/> 
                                        <telerik:RadMenuItem runat="server" Text="Speichern"/> 
                                    </Items> 
                                </telerik:RadMenuItem> 
                                <telerik:RadMenuItem runat="server" Text="Löschen" /> 
                            </Items> 
                        </telerik:RadTreeViewContextMenu> 
                        <telerik:RadTreeViewContextMenu ID="ctm_NormMenu" runat="server" Skin="Default">                         
                            <Items> 
                                <telerik:radmenuitem runat="server" Text="Add to Favorits" /> 
                            </Items> 
                        </telerik:RadTreeViewContextMenu> 
                    </ContextMenus> 
                </telerik:RadTreeView>     
            </telerik:RadAjaxPanel>               
        </div>  
 
    <telerik:RadScriptBlock ID="rsb_getTree" runat="server"
        <script type="text/javascript" language="javascript"
            var tree; 
            window.onbeforeunload = onRequestStart
 
            function setTree(sender, eventArgs) { 
                tree = $find('<%=rtv_Menue.ClientID%>'); 
            } 
 
            function createCookie() { 
                var toggleActions = ""
                var nodes; 
                var node; 
 
                nodes = tree.get_allNodes(); 
 
                for (var i = 1; i < nodes.length; i++) { 
                    node = nodes[i] 
                    if (node.get_expanded()) { 
                        toggleActions += node.get_value() + '*'; 
                    } 
                } 
                var date = new Date(); 
                date.setTime(date.getTime() + (1 * 24 * 60 * 60 * 1000)); 
                var expires = "; expires=" + date.toGMTString(); 
 
                document.cookie = "TreeToggleActions=" + toggleActions + expires + "; path=/"; 
            } 
 
            function onRequestStart(sender, arguments) { 
                createCookie(); 
            } 
 
            function onResponseEnd(sender, arguments) { 
                isUpdatingAppointment = false
            } 
 
            function ClientContextMenuShowing(sender, eventArgs) { 
                var node = eventArgs.get_node(); 
                var menu = eventArgs.get_menu();
                var items = menu.get_items(); //Error is thrown here, "menu is null"
 
                document.getElementById('txt_FavNamechng').value = node.get_text(); 
                document.getElementById('txt_FavURLchng').value = node.get_navigateUrl(); 
 
            } 
 
        </script> 
    </telerik:RadScriptBlock> 
 
    </form> 
</body> 
</html> 
 


And the CodeBehind:
Imports Telerik.Web.UI 
 
Public Class test 
    Inherits System.Web.UI.Page 
 
    Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load 
        Dim node = New RadTreeNode() 
        node.Text = "TestNode" 
        node.ContextMenuID = "ctm_FavMenu" ''same with ctm_NormMenu 
        rtv_Menue.Nodes.Add(node) 
    End Sub 
 
End Class 



Any help is appreciated,

Lukas

1 Answer, 1 is accepted

Sort by
0
Accepted
Nikolay Tsenkov
Telerik team
answered on 10 Jun 2010, 01:25 PM
Hi Lukas,

This error was caused, because you set ClientIDMode to "Static" on the treeView. Please remove it and then the line:
var items = menu.get_items()
won't result in error.

Hope this is going to help you!


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.
Tags
TreeView
Asked by
Lukas
Top achievements
Rank 2
Answers by
Nikolay Tsenkov
Telerik team
Share this question
or