Client-Side Script for ContextMenu Causes Error

2 posts, 0 answers
  1. PJ Rodriguez
    PJ  Rodriguez avatar
    37 posts
    Member since:
    Feb 2005

    Posted 10 Feb 2012 Link to this post

    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>

  2. PJ Rodriguez
    PJ  Rodriguez avatar
    37 posts
    Member since:
    Feb 2005

    Posted 13 Feb 2012 Link to this post

    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 */
                }

Back to Top