ContextMenu Right click in a Listbox

3 posts, 1 answers
  1. Robert Canal
    Robert Canal avatar
    17 posts
    Member since:
    Mar 2010

    Posted 08 Feb 2011 Link to this post

    When you right click on an item in the ListBox it works as expected.  But if you right click in the ListBox but not on an item it gives me the following error any ideas on how to correct this?

    "Microsoft JScript runtime error: 'get_item()' is null or not an object"

     

    function showContextMenu(sender, e) {

     

     

    var RadList = $find("Listbox");

     

     

    var RadListSelected = RadList.get_selectedItem();

     

     

    var menu = $find("cm1");

     

     

    var rawEvent = e.get_domEvent().rawEvent;

     

    menu.show(rawEvent);

    e.get_item().select();  < ERROR is called on this item because object is nothing

    $telerik.cancelRawEvent(rawEvent);

    }

  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 09 Feb 2011 Link to this post

    Hello Robert,

    I suppose you are showing the ContextMenu based on the clicked menu item. So if you right click on the ListBox other than an item, there won't be any item and e.get_item() will be null, that's why the error comes. So one suggestion is to check whether e.get_item() is null or not, before showing the ContextMenu. Here is a sample code.

    <script type="text/javascript">
     function showContextMenu(sender, e)
      {
             if (e.get_item() == null)
              {
                e.get_domEvent().preventDefault();//prevents showing the browser menu
                return;
             }
           var menu = $find("<%= cm1.ClientID %>");
           . . . . . . . . . . . . .
     }
    </script>

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Robert Canal
    Robert Canal avatar
    17 posts
    Member since:
    Mar 2010

    Posted 09 Feb 2011 Link to this post

    That was what I need thanks....I am very new to javascript so I wasn't aware of the " e.get_domEvent().preventDefault();//prevents showing the browser menu  " event.

Back to Top