Context menu not working with master page

2 posts, 0 answers
  1. Nabarun
    Nabarun avatar
    2 posts
    Member since:
    Apr 2013

    Posted 16 Sep 2013 Link to this post

    HI,
    Below is my requirement,
    Need to attach Rad context Menu on right click in side an asp.net text-box control.

    I have used context menu example given in
    http://demos.telerik.com/aspnet-ajax/menu/examples/contextmenu/default/defaultcs.aspx

    This is working on a normal asp.net web page, but when ever I use master page context menu is not working any more. Below is the aspx page code
    <%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="TestPageWithMasterPage.aspx.cs" Inherits="TestPageWithMasterPage" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
     
    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <telerik:RadContextMenu runat="server" ID="ChooseDesktopImage"
              EnableRoundedCorners="true" EnableShadows="true" OnClientItemClicked="chooseDesktopImageItemClicked">
                        <Targets>
                            <telerik:ContextMenuElementTarget ElementID="desktop" />
                        </Targets>
                        <Items>
                            <telerik:RadMenuItem Text="Beach" Value="Beach" />
                            <telerik:RadMenuItem Text="Field" Value="Field" />
                            <telerik:RadMenuItem Text="House" Value="House" />
                        </Items>
         </telerik:RadContextMenu>
            <asp:TextBox ID="desktop" runat="server"></asp:TextBox>
     
             <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
              <script type="text/javascript">
                  function showingSetAsDesktop(sender, args) {
                      //Disable the setAsDesktop menu on the desktop image
                      if (args.get_targetElement().id == "desktop") {
                          args.set_cancel(true);
                      }
                  }
     
                  function chooseDesktopImageItemClicked(sender, args) {
                      $get("desktop").value = args.get_item().get_value();
                  }
              </script>
         </telerik:RadScriptBlock>
    </asp:Content>


    Thanks,
    Nabarun.
  2. Kate
    Admin
    Kate avatar
    1898 posts

    Posted 17 Sep 2013 Link to this post

    Hi Nabarun,

    Note that when using a master page and a content page the id of the controls on the content page changes (here you can read more on this topic) and therefore you get this issue. To get the contextmenu work as expected on your page you can either set the ClientIDMode="Static" property of the TextBox or change the id that you assign to the RadContextMenu so it matches the rendered id:
    <asp:TextBox ID="desktop" runat="server" ClientIDMode="Static"></asp:TextBox>

    Regards,
    Kate
    Telerik
    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 the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top