RadContextMenu - Can't add targets via TagName for custom elements

2 posts, 0 answers
  1. Elio Querze
    Elio Querze avatar
    1 posts
    Member since:
    Oct 2009

    Posted 07 Sep 2010 Link to this post

    I have a bunch of custom html elements being generated by user controls in my web page, but I'm having a hard time getting them set as targets for the context menu. The following doesn't seem to work:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TelerikTest1._Default" %>
      
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
      
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      
    <head runat="server">
        <title></title>
    </head>
    <body>
        <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
        <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
        <script language="javascript">
      
            function TokenContextMenu_Clicked(sender, args)
            {
                var menuItemValue = args.get_item().get_value();
                if (menuItemValue == "DefineDictionaryItem")
                {
                    alert("Success!");
                }
            }
    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
        <telerik:RadContextMenu ID="TokenContextMenu" runat="server" OnClientItemClicked="TokenContextMenu_Clicked">
            <Targets>
                <telerik:ContextMenuTagNameTarget TagName="text_token" />
            </Targets>
            <Items>
                <telerik:RadMenuItem runat="server" Text="Define Dictionary Item" Value="DefineDictionaryItem" />
            </Items>
        </telerik:RadContextMenu>
        <div>
            <text_token id="text_token_1">Thisisatesttoken1!</text_token>
            <text_token id="text_token_2">Thisisatesttoken2!</text_token>
        </div>
        </form>
    </body>
    </html>
  2. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 14 Sep 2010 Link to this post

    Hi Elio Querze,

    Let me suggest you add a ContextMenuElementTarget instead of ContextMenuTagNameTarget and respectively use the control IDs instead of tag names:
    <telerik:RadContextMenu ID="TokenContextMenu" runat="server">
        <Targets>
            <telerik:ContextMenuElementTarget ElementID="text_token_1_ucerControl" />
            <telerik:ContextMenuElementTarget ElementID="text_token_2_ucerControl" />
            <telerik:ContextMenuTagNameTarget TagName="div" />
        </Targets>
        <Items>
            <telerik:RadMenuItem runat="server" Text="Define Dictionary Item"
                Value="DefineDictionaryItem" />
        </Items>
    </telerik:RadContextMenu>
    <div>
        <text:token ID="text_token_1" runat="server" Word="Thisisatesttoken1!" />
        <br />
        <text:token ID="text_token_2" runat="server" Word="Thisisatesttoken2!" />
    </div>

    Since I have no information what is your user control implementation - I created this simplified control:
    <%@ Control Language="C#" AutoEventWireup="true"
        CodeFile="text_token.ascx.cs" Inherits="Menu_text_token" %>
    <div id="ucerControl" runat="server"
        style="background-color: #CCCCCC; height: 80px; width: 140px;" >
        <asp:Literal ID="ltrWord" runat="server"></asp:Literal>
    </div>

    public partial class Menu_text_token : System.Web.UI.UserControl
    {
        string word;
     
        public string Word
        {
            get { return word; }
            set { word = value; }
        }
     
        protected void Page_Load(object sender, EventArgs e)
        {
            this.ltrWord.Text = Word;
        }
    }

    Please find more details at the sample attached. I hope this helps.

    Greetings,
    Kalina
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top