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

Client-Side Script for ContextMenu Causes Error

1 Answer 51 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
PJ Rodriguez
Top achievements
Rank 1
PJ Rodriguez asked on 11 Feb 2012, 12:58 AM
I have a RADTreeView that I build programmatically.

The same RADTreeView has ContextMenus built during design time. I've attached the script below on the RADTreeview's OnClientContextMenuShowing as below. The issue I have is that this only works for the nodes that have "isApproved" attributes. If right-click anywhere else in the RADTreeView, I get an error that says "Unable to get value of the property 'get_id': object is null or undefined".

My concept is that the get_id method shouldn't be called unless the context menu id is what I have stated below. It seems to be getting called not matter what. Your help is appreciated.

<telerik:RadTreeView ID="RadTreeView1" runat="server" OnClientContextMenuShowing="ClientContextMenuShowing">

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
       <script type="text/javascript" language="javascript">
 
           function ClientContextMenuShowing(sender, eventArgs) {
               var node = eventArgs.get_node();
               var menu = eventArgs.get_menu();
               var domEvent = eventArgs.get_domEvent();
 
               /* Change value of context menu based on whether an item is approved or not is Consent
               Agenda */
               if (menu.get_id() == "ctl00_ContentPlaceHolder1_RadTreeView1_cmOtherApprovalsAgenda") {
                   var attributes = node.get_attributes();
                   attributes.getAttribute("isApproved");
                   if (attributes.getAttribute("isApproved") == "Yes") {
                       menu.findItemByValue("cmOtherApprovalsAgendaApproveAB").set_text("UnApprove Agenda Bill");
                   }
                   else {
                       menu.findItemByValue("cmOtherApprovalsAgendaApproveAB").set_text("Approve Agenda Bill");
                   }
               }
           }       
       </script>
   </telerik:RadCodeBlock>

1 Answer, 1 is accepted

Sort by
0
PJ Rodriguez
Top achievements
Rank 1
answered on 13 Feb 2012, 11:57 PM

The following script change seems to have resolved the issue:

function ClientContextMenuShowing(sender, eventArgs) {
                /* Change value of context menu based on whether an item is approved or not is Consent
                Agenda */
                var node = eventArgs.get_node();
                var menu = eventArgs.get_menu();
                if (node.get_attributes().getAttribute("isApproved") == "Yes") {
                    menu.findItemByValue("cmOtherApprovalsAgendaApproveAB").set_text("UnApprove Agenda Bill");
                }
                if (node.get_attributes().getAttribute("isApproved") == "No") {
                    menu.findItemByValue("cmOtherApprovalsAgendaApproveAB").set_text("Approve Agenda Bill");
                }
                /* Change value of context menu based on whether an item is approved or not is Consent
                Agenda */
            }

Tags
TreeView
Asked by
PJ Rodriguez
Top achievements
Rank 1
Answers by
PJ Rodriguez
Top achievements
Rank 1
Share this question
or