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

Adding a Content Template to Dynamically Created Menu Item

3 Answers 69 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Support
Top achievements
Rank 1
Support asked on 15 Sep 2014, 04:34 PM
I have a basic menu created successfully, but would like to have a template applied to a couple dynamically created items.

I would like to have a User Control be the contents so that the management of the content can be controlled separately.

So my basic scenario is this:

Create Root Menu item, Create Sub item, Apply ItemTemplate, Create New Sub Item, Undo Template...

My Template is such:


'ItemTemplate Class. Just pulls the User Control
Class QC_HACCP_Hold
        Implements ITemplate
        Public Sub InstantiateIn(ByVal container As Control) Implements ITemplate.InstantiateIn
            Dim lit1 As New QC_HACCP_Hold_Lot
            container.Controls.Add(lit1)
        End Sub
    End Class
 
 
'User Control write up - QC_HACCP_Hold_Lot
 
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="QC_HACCP_Hold_Lot.ascx.vb" Inherits="sadlersnet.QC_HACCP_Hold_Lot" %>
<asp:panel id="pnlHold" runat="server">
    <p>
        Enter Lot Number to Place on Hold<br />
        <asp:TextBox ID="txtLotNumber" runat="server"></asp:TextBox><asp:Button ID="cmdHoldLot" runat="server" Text="Set to Hold" />
    </p>
</asp:panel>
 
'Code to Create Parent and Sub with Template Applied
        Dim _QCHACCP_Place_Lot_On_Hold As RadMenuItem = AddMenuItem("Place Lot on Hold", Nothing, False)
        With _QCHACCP_Place_Lot_On_Hold
            Dim _QC_HoldTemplate As New Custom_Rad_Templates.QC_HACCP_Hold
            mnuMain.ItemTemplate = _QC_HoldTemplate
            .Items.Add(New RadMenuItem)
   
        End With
 
'Helper function for creating menuitems
Private Function AddMenuItem(ByVal Caption As String, URL As String, ByVal AutoPostBack As Boolean, Optional ByVal Target As String = Nothing) As RadMenuItem
        Dim _MenuItem As RadMenuItem = New RadMenuItem
        _MenuItem.PostBack = AutoPostBack
        _MenuItem.NavigateUrl = URL
        _MenuItem.Text = Caption
        If Not IsNothing(Target) Then _MenuItem.Target = Target
        Return _MenuItem
    End Function

Im getting the Parent and it knows theres a sub, and expanding just gives me a little tiny box with no content...

Any Ideas?

3 Answers, 1 is accepted

Sort by
0
Support
Top achievements
Rank 1
answered on 15 Sep 2014, 05:51 PM
Addendum. I have changed the code to include the InstatiateIn:
With _QCHACCP_Place_Lot_On_Hold
            Dim _QC_HoldTemplate As New Custom_Rad_Templates.QC_HACCP_Hold
            mnuMain.ItemTemplate = _QC_HoldTemplate
            .Items.Add(New RadMenuItem)
        End With

This still does not change the outcome...unfortunately
0
Support
Top achievements
Rank 1
answered on 15 Sep 2014, 05:53 PM
Scratch prev post..cut and paste did not work right:

Correct Change
With _QCHACCP_Place_Lot_On_Hold
            Dim _Template As New Custom_Rad_Templates.QC_HACCP_Hold
            Dim _X As New RadMenuItem
            _Template.InstantiateIn(_X)
            .Items.Add(_X)
        End With
0
Dimitar Terziev
Telerik team
answered on 18 Sep 2014, 03:58 PM
Hi,

There is a problem with the dynamic creating of the Content Template for the RadMenu control. Currently it could be defined only from the markup.

Regards,
Dimitar Terziev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Menu
Asked by
Support
Top achievements
Rank 1
Answers by
Support
Top achievements
Rank 1
Dimitar Terziev
Telerik team
Share this question
or