Adding context menu dynamically giving error

2 posts, 1 answers
  1. shadow
    shadow avatar
    58 posts
    Member since:
    Jun 2008

    Posted 05 Nov 2012 Link to this post

    I am trying to show a context menu on mouse over of an image control.

    Below is my code

               
    Dim ControlsContainer As New Panel
               Dim InfoIcon As New Image
               Dim InfoContextMenu As New RadContextMenu
               Dim mi As New RadMenuItem
     
     
     
     
     
     
               ControlsContainer.ID = "pnlInfoContainer"
     
     
     
     
               InfoIcon.ID = "InfoImageIcon"
               InfoIcon.ImageUrl = "/mb/admin/images/plus.png"
               InfoIcon.Attributes.Add("onmouseover", "ShowInfoMenuOnLeftClick();")
     
     
     
     
               InfoContextMenu.ID = "mb_InfoContents_ContentextMenu"
               InfoContextMenu.ClientIDMode = System.Web.UI.ClientIDMode.Static
     
     
     
     
               mi.Text = "Home"
               InfoContextMenu.Items.Add(mi)
     
     
     
     
               ControlsContainer.Controls.Add(InfoIcon)
               ControlsContainer.Controls.Add(InfoContextMenu)
     
     
     
     
               Dim script As String = "<script type=""text/javascript""> function ShowInfoMenuOnLeftClick(sender, args) {     var contextMenu = $find('mb_InfoContents_ContentextMenu'); console.log(contextMenu); contextMenu.show(args); } </script>"
               If Not Me.Page.ClientScript.IsStartupScriptRegistered("InfocontentsMenu") Then
                   Me.Page.ClientScript.RegisterStartupScript(Me.Page.GetType, "InfocontentsMenu", script)
               End If
     
     
               Me.Controls.Add(ControlsContainer)
     
     
     
     
               Dim MenuTargetConfiguration As New ContextMenuControlTarget()
               MenuTargetConfiguration.ControlID = "InfoImageIcon"
               InfoContextMenu.Targets.Add(MenuTargetConfiguration)



    I am getting a java script error with this code..

    1. Uncaught TypeError: Cannot read property 'target' of undefined Telerik.Web.UI.WebResource.axd:4660
      1. ShowInfoMenuOnLeftClickindex.aspx:560
      2. onmouseover

    Can you help me!!
  2. Answer
    Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 07 Nov 2012 Link to this post

    Hello Farid,

    I prepared a sample project that demonstrates how you can find the RadContextMenu when is either created in code behind or in the markup. I would also recommend you take a look at this online demo that shows how a context menu pops up on image hover.

    Hope that this will lead you into right direction.

    Regards,
    Boyan Dimitrov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top