Integrate RadMenu with Sharepoint problem

3 posts, 0 answers
  1. Nishim Attreja
    Nishim Attreja avatar
    2 posts
    Member since:
    Jun 2008

    Posted 07 Jul 2008 Link to this post

    Hello there,

    I am trying to create Contextmenu from RadMenu.Net2 version 4.4.5.0.
    I am integrating this contextmenu with radtreeview.net2

    ContextMenu code is given below in webpart:
    relatedDocContextMenu = new RadMenu();
                relatedDocContextMenu.ID = "relDocContextMenu";
                relatedDocContextMenu.IsContext = true;
                relatedDocContextMenu.RadControlsDir = "/_wpresources/RadMenu.Net2/4.4.5.0_bbe59a8ad3533e68/RadControls";

                SPWeb oWeb = null;
                oWeb = SPContext.Current.Web;
                //Adding RadConTextMenu Items
                RadMenuItem itmFavorite = new RadMenuItem("Add Favorite");
                itmFavorite.ImageUrl = oWeb.Url + "/images/favstar.gif";

                relatedDocContextMenu.Items.Add(itmFavorite);

                RadMenuItem itmEmail = new RadMenuItem("Email");
                itmEmail.ImageUrl = oWeb.Url + "/images/favstar.gif";

                relatedDocContextMenu.Items.Add(itmEmail);

                RadMenuItem itmAlert = new RadMenuItem("Set Alert");
                itmAlert.ImageUrl = oWeb.Url + "/images/favstar.gif";

                relatedDocContextMenu.Items.Add(itmAlert);



                relatedDocContextMenu.ContextMenuElementID = "none";
                relatedDocContextMenu.UseEmbeddedScripts = false;


                apnlRelated.Controls.Add(relatedDocContextMenu);
    ====
    apnlRelated is RadAjaxPanel in whic tree is also there.
    =======================

    Code to add contextmenu in treeview:
    tvRelated = new RadTreeView();
                tvRelated.ID = "tvRelated";
                tvRelated.BeforeClientClick = "BeforeClientClickHandler";
                tvRelated.BeforeClientContextMenu = "ShowRadMenu";
                tvRelated.RadControlsDir = "/_wpresources/RadControls/";
                //tvRelated.ShowLineImages = false;
                //tvRelated.ImagesBaseDir = "/_wpresources/RadControls/Treeview/Skins";
                tvRelated.Skin = "Color";
                tvRelated.NodeBound += new RadTreeView.RadTreeViewEventHandler(tvRelated_NodeBound);
    ==========
    script for ShowRadMenu:
    ===
    private const string relatedDocConTextMenuScriptKey = "RelatedDocConextMenu";
            private string relatedRadContextMenuScript = "<script language='javascript' type='text/javascript'>";

                relatedRadContextMenuScript += "function ShowRadMenu(node, e)";
                relatedRadContextMenuScript += "{    ";
                relatedRadContextMenuScript += " var menu = null; ";
                //relatedRadContextMenuScript += "if (node.Category == 'Folder')";
                //relatedRadContextMenuScript += "{";
                //relatedRadContextMenuScript += "   menu = window['<%= relatedDocContextMenu.ClientID %>'];";window['ctl00_m_g_197245f5_94be_4c1a_8fb1_8a924e6e7f33_relDocContextMenu'];
                //relatedRadContextMenuScript += "}";
                //relatedRadContextMenuScript += "else";
                //relatedRadContextMenuScript += "{";
                relatedRadContextMenuScript += " alert(window['<%= relDocContextMenu.ClientID %>']);  menu = window['<%= relDocContextMenu.ClientID %>']; ";
                //relatedRadContextMenuScript += "}";
                relatedRadContextMenuScript += "  if (menu)";
                relatedRadContextMenuScript += "{";
                relatedRadContextMenuScript += "   menu.Show(e);";
                relatedRadContextMenuScript += "   e.cancelBubble = true;";
                relatedRadContextMenuScript += "   if (e.stopPropagation)";
                relatedRadContextMenuScript += "  {";
                relatedRadContextMenuScript += "e.stopPropagation();";
                relatedRadContextMenuScript += "   }";
                relatedRadContextMenuScript += " e.returnValue = false;";
                relatedRadContextMenuScript += "if (e.preventDefault)";
                relatedRadContextMenuScript += " {";
                relatedRadContextMenuScript += "    e.preventDefault();";
                relatedRadContextMenuScript += "}";
                relatedRadContextMenuScript += "}";
                relatedRadContextMenuScript += "}";
                relatedRadContextMenuScript += "</script>";
    ================
    My problem is when i am right click on treenode this conextmenu should show. Is is calling the ShowRadMenu  funtion but it is not detecting RadMenu object.
    alert(window['<%= relDocContextMenu.ClientID %>']);
    The Above alert is showing "undefined";

    SafeControls Entries:
    <SafeControl Assembly="RadMenu.Net2, Version=4.4.5.0, Culture=neutral, PublicKeyToken=bbe59a8ad3533e68" Namespace="Telerik.WebControls" TypeName="*" Safe="True" />

    <SafeControl Assembly="RadMenu.Net2, Version=4.4.5.0, Culture=neutral, PublicKeyToken=bbe59a8ad3533e68" Namespace="Telerik.RadMenuUtils" TypeName="*" Safe="True" />

    I also tried with var menu = <%= relDocContextMenu.ClientID %>;
    but no luck.
    I also unchecked in configuration .axd - with "verify that file Exists".

    Please help me out in this.

    Thanks and Regards,
    Nishim Attreja

  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 08 Jul 2008 Link to this post

    Hello Nishim Attreja,

    You should use the following code to get the menu client-side object:

    relatedRadContextMenuScript += "var menu = window['" + relatedDocContextMenu.ClientID +"']";

    ['<%= relatedDocContextMenu.ClientID %>'] cannot be used from codebehind because it is a server-side expression evaluated when the ASP.NET runtime parses the ASPX file for the first time.

    Regards,
    Albert
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

  3. Nishim Attreja
    Nishim Attreja avatar
    2 posts
    Member since:
    Jun 2008

    Posted 08 Jul 2008 Link to this post

    Thanks Albert,

    It worked like a charm.. Thanks again.

    Thanks and Regards,
    Nishim Attreja


Back to Top