This is a migrated thread and some comments may be shown as answers.

Context menu not working with master page

1 Answer 34 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Nabarun
Top achievements
Rank 1
Nabarun asked on 16 Sep 2013, 08:36 AM
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.

1 Answer, 1 is accepted

Sort by
0
Kate
Telerik team
answered on 17 Sep 2013, 09:54 AM
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.
Tags
Menu
Asked by
Nabarun
Top achievements
Rank 1
Answers by
Kate
Telerik team
Share this question
or