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

Ajax-enable WCF Menu not populating items

2 Answers 63 Views
Menu
This is a migrated thread and some comments may be shown as answers.
louis chan
Top achievements
Rank 1
Iron
louis chan asked on 26 Jul 2010, 07:41 PM
Hi guys,

According to this help:
http://www.telerik.com/help/aspnet-ajax/menu-populate-from-wcf-service.html

I can successfully run OnClientItemPopulatingHandler and there is debug breakpoint that show me GetData is run and the items.count is 4. After that,there is no any radmenu drop-down as expected. Here is the code:

Mark-up
<!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>
    <script type="text/javascript">
        function OnClientItemPopulatingHandler(sender, e) {
            var context = e.get_context();
            //using jQuery to get the checked item and pass it to the server
            context["ProductSuite"] = $telerik.$("input[name='rblSuites']:checked").val();
        }
 
        function OnClientItemPopulatedHandler(sender, e) {
            var items = e.get_item().get_items();
            for (var i = 0; i < items.get_count(); i++) {
                var item = items.getItem(i);
                //getting the attribute of the item
                var myCustomAttribute = item.get_attributes().getAttribute("MyCustomAttribute");
                //do something with the attribute
            }
        }
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
        <asp:RadioButtonList ID="rblSuites" runat="server">
           <asp:ListItem Selected="True">ASP.NET AJAX</asp:ListItem>
           <asp:ListItem>WPF</asp:ListItem>
           <asp:ListItem>Silverlight</asp:ListItem>
           <asp:ListItem>Winforms</asp:ListItem>
        </asp:RadioButtonList>    
     
        <telerik:RadMenu ID="RadMenu1"
           OnClientItemPopulating="OnClientItemPopulatingHandler"
           OnClientItemPopulated="OnClientItemPopulatedHandler"
           runat="server">
           <Items>
               <telerik:RadMenuItem Text="Products" ExpandMode="WebService">
               </telerik:RadMenuItem>
           </Items>
           <WebServiceSettings Method="GetData" Path="../Services/WcfTopMenu.svc" />
        </telerik:RadMenu>
    </div>
    </form>
</body>
</html>

.SVC
<%@ ServiceHost Language="VB" Debug="true" Service="WcfTopMenu" CodeBehind="~/App_Code/WcfTopMenu.vb" %>

svc code behind

Imports System.ServiceModel
Imports System.ServiceModel.Activation
Imports System.ServiceModel.Web
Imports Telerik.Web.UI
 
<ServiceContract([Namespace]:="")> _
<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)> _
Public Class WcfTopMenu
    <OperationContract()> _
    Public Function GetData(ByVal item As RadMenuItemData, ByVal context As IDictionary(Of String, Object)) As RadMenuItemData()
        Dim items As New List(Of RadMenuItemData)()
        'use the context to get the selected radio button
        Dim productsSuite As String = context("ProductSuite").ToString()
        'the datasource
        'Dim radControls() As String = New String() {"RadMenu", "RadMenu", "RadTreeView", "RadToolBar"}
        Dim radControls As List(Of [String]) = New List(Of String)() From { _
           "RadMenu", _
           "RadMenu", _
           "RadTreeView", _
           "RadToolBar" _
          }
        For Each radControl As String In radControls
            'Optional: set the attribute of the item which will be used
            'in the OnClientNodePopulated event
            Dim newItem As New RadMenuItemData() With { _
             .Text = String.Format("{0} for {1}", radControl, productsSuite), _
             .Value = radControl, _
             .ImageUrl = "Images/" + radControl + ".gif", _
             .Attributes = New Dictionary(Of String, Object)() From {{"MyCustomAttribute", radControl}}
            }
            items.Add(newItem)
        Next
        Return items.ToArray()
    End Function
End Class


Did I miss sth? If so, please tell me. Thx!

2 Answers, 1 is accepted

Sort by
0
louis chan
Top achievements
Rank 1
Iron
answered on 27 Jul 2010, 02:50 AM
Q2.
According to "C:\Program Files\Telerik\RadControls for ASP.NET AJAX Q2 2010\Live Demos\App_Code\MenuWcfService.cs"
Is that I need 2 data source to get Hierarchical menu and 2 condition checking to find out the on-demand menu whether contains any sub menu in WCF? Thx!
0
Accepted
Yana
Telerik team
answered on 30 Jul 2010, 08:23 AM
Hi louis,

Actually there's no need for two datasources and also you should know weather an items has subitems in order to set its ExpandMode. Could you please prepare a simple page demonstrating the issue and send it to us? You should open a support ticket and attach it there. Thanks in advance

Regards,
Yana
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
Tags
Menu
Asked by
louis chan
Top achievements
Rank 1
Iron
Answers by
louis chan
Top achievements
Rank 1
Iron
Yana
Telerik team
Share this question
or