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

[Solved] Sub menu items are not showing up

1 Answer 255 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Han
Top achievements
Rank 1
Han asked on 11 May 2009, 09:27 PM
Hi,

I tried to test a dynamic menu control, and everything is fine except the sub menu items are not showing up.

What I am thinking is that when this dynamic control is inherited from RadMenu, it does not inherit the javascript side of the control. In other words, the behaviors of the control does not automatically inherits from the RadMenu.

Here, it only shows "aaa" in the first level, but "bbb" is not showed up when I hovered on the "aaa".
namespace AjaxServerControl1  
{  
    [ClientScriptResource("Telerik.Web.UI.RadMenu""Telerik.Web.UI.Menu.RadMenuScripts.js")]  
    [Designer("Telerik.Web.Design.RadMenuDesigner, Telerik.Web.UI, Version=2008.03.1125.20, Culture=neutral, PublicKeyToken=121fae78165ba3d4")]  
    public class ServerControl1 : RadMenu, IScriptControl  
    {  
        protected override IEnumerable<ScriptDescriptor>  
                GetScriptDescriptors()  
        {  
            ScriptControlDescriptor descriptor = new ScriptControlDescriptor("AjaxServerControl1.ClientControl1"this.ClientID);  
            yield return descriptor;  
        }  
 
        // Generate the script reference  
        protected override IEnumerable<ScriptReference>  
                GetScriptReferences()  
        {  
            yield return new ScriptReference("AjaxServerControl1.ClientControl1.js"this.GetType().Assembly.FullName);  
        }
        #region IScriptControl Members  
 
        IEnumerable<ScriptDescriptor> IScriptControl.GetScriptDescriptors()  
        {  
            return GetScriptDescriptors();  
        }  
 
        IEnumerable<ScriptReference> IScriptControl.GetScriptReferences()  
        {  
            return GetScriptReferences();  
        }
        #endregion  
    }  
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>  
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>  
 
<%@ Register Assembly="AjaxServerControl1" Namespace="AjaxServerControl1" TagPrefix="cc"%>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
 
<html xmlns="http://www.w3.org/1999/xhtml">  
<head runat="server">  
    <title>Untitled Page</title>  
</head>  
<body>  
    <form id="form1" runat="server">  
    <div>  
    <telerik:RadScriptManager ID="RadScriptManager1" Runat="server"></telerik:RadScriptManager>  
        <cc:ServerControl1 ID="menu" runat="server">  
            <Items>  
                <telerik:RadMenuItem Text="aaa">  
                    <Items>  
                        <telerik:RadMenuItem Text="bbb"></telerik:RadMenuItem>  
                    </Items>  
                </telerik:RadMenuItem>  
            </Items>  
        </cc:ServerControl1>  
    </div>  
    </form>  
</body>  
</html> 

Anyone has any advise or an alternative solution?
Thanks.

1 Answer, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 14 May 2009, 02:03 PM
Hello Han,

RadMenu implements the IScriptControl through its hierarchical parent RadDataBoundControl (as seen in the online documentation) - the script references are registered there, as follows:
        IEnumerable<ScriptDescriptor> IScriptControl.GetScriptDescriptors()
        {
            return GetScriptDescriptors();
        }

        protected virtual IEnumerable<ScriptDescriptor> GetScriptDescriptors()
        {
            return ScriptRegistrar.GetScriptDescriptors(this);
        }

        IEnumerable<ScriptReference> IScriptControl.GetScriptReferences()
        {
            return GetScriptReferences();
        }

        protected virtual IEnumerable<ScriptReference> GetScriptReferences()
        {
            List<ScriptReference> refs = new List<ScriptReference>();
            if (EnableEmbeddedScripts)
            {
                refs.AddRange(ScriptRegistrar.GetScriptReferences(GetType()));
            }
            return refs;
        }


You should modify your code to include these, too, and the client-side behavior should be as expected.

Regards,
Alex
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Menu
Asked by
Han
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Share this question
or