Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Menu > Template dynamic creation
RadControls for ASP.NET are no longer supported (see this page for reference). In case you have inquiries about the Telerik ASP.NET AJAX controls, post them in the pertinent ASP.NET AJAX forums.

Not answered Template dynamic creation

Feed from this thread
  • luc bonenfant avatar

    Posted on Feb 18, 2008 (permalink)

    Hello,
    I'm creating a sub-menu dynamically, this menu is a template.
    The template is not rendered, why please ?

    This is the static code, which is functionnal :

     
                                <radM:RadMenu ID="rmFiles" runat="server" Skin="Vista" OnClientItemClicking="OnClicking">  
                                    <Items> 
                                        <radM:RadMenuItem Text="Files" ImageUrl="Images\Folders\File.gif" Width="100%" Font-Bold="true">  
                                            <Items> 
                                                <radM:RadMenuItem Value="Delete" Text="Delete file" ImageUrl="Images\Actions\Delete.gif" /> 
                                                <radM:RadMenuItem Value="Rename" Text="Rename file" ImageUrl="Images\Actions\Rename.gif">  
                                                <Items> 
                                                    <radM:RadMenuItem Value="EditRename">  
                                                        <ItemTemplate> 
                                                            <asp:TextBox ID="txEditFile" runat="server" Width="250" MaxLength="255" /> 
                                                            <asp:LinkButton ID="lkEditFile" runat="server" Text="OK" OnClick="OnFileEditing" /> 
                                                        </ItemTemplate> 
                                                    </radM:RadMenuItem> 
                                                </Items> 
                                                </radM:RadMenuItem> 
                                            </Items> 
                                        </radM:RadMenuItem> 
                                    </Items> 
                                </radM:RadMenu> 

    This is the "same" code but added dynamically, which is failed for template visibility :

     
        Private Sub LoadMenu()  
     
     
                rmFiles.Items.Clear() 'rmFiles is a radMenu  
                Dim RootMenu As RadMenuItem = AddMenuItem(String.Empty, "Files")  
                rmFiles.Items.Add(RootMenu)  
                Dim DeleteMenu As RadMenuItem = AddMenuItem("Delete""Delete file")  
                RootMenu.Items.Add(DeleteMenu)  
                Dim RenameMenu As RadMenuItem = AddMenuItem("Rename""Rename file")  
                RootMenu.Items.Add(RenameMenu)  
                Dim EditRename As RadMenuItem = AddMenuItem("EditRename"String.Empty)  
                EditRename.ItemTemplate = New RenameTemplate()  
                RenameMenu.Items.Add(EditRename)  
     
            End Sub 
     
     
            Private Function AddMenuItem(ByVal Value As StringByVal Text As StringAs RadMenuItem  
     
                Dim rmItem As New RadMenuItem  
                rmItem.Value = Value  
                rmItem.Text = Text  
     
                Return rmItem  
     
            End Function 
     
            Public Class RenameTemplate  
                Implements System.Web.UI.ITemplate  
     
                Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn  
     
                    Dim txEditFile As New TextBox  
                    txEditFile.Width = Unit.Pixel(250)  
                    container.Controls.Add(txEditFile)  
     
                    Dim lkEditFile As New LinkButton  
                    lkEditFile.Text = "OK" 
                    'AddHandler lkEditFile.Click, AddressOf lkEditFile_Click  
                    container.Controls.Add(lkEditFile)  
     
                End Sub 
     
            End Class 

    I notice that if the template is child of RootMenu (instead of subchild), the template is visible...

    Thank you for help.
    Etienne.

  • Posted on Feb 19, 2008 (permalink)

    Hi,

    Go through the following help document links given below.

    Add items dynamically
    Define the structure programmatically

    Shinu.

  • luc bonenfant avatar

    Posted on Feb 19, 2008 (permalink)

    It's exactly what I did for creating children nodes... see above.
    Therefore, my template is not visible. RadMenu help is poor about templates, so I tried method red in Treeview Help :
    - How to add controls to the node's Controls collection at run time
    - How to add and edit templates Runtime
    It gave the extract of proposed code above with Instantiate In method. I tested also the Node1.Controls.Add(aTextBox) method, and it doesn't work any more.
    Can you send me please a part of code to insert sub-node with template, whith a correct render please ?

  • Peter Peter admin's avatar

    Posted on Feb 19, 2008 (permalink)

    Hello Luc,

    Please see the topic on how to How to add templates (controls) runtime. It is for RadPanelbar, but the same approach applies for RadMenu as well. Let us know if you have any questions.



    Regards,
    Peter
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

  • luc bonenfant avatar

    Posted on Feb 19, 2008 (permalink)

    Same problem, doesn't change anything by changing commented code in first line by the other in second line.

    'MenuItem11.Controls.Add(txEditFile)
    rmFiles.Items(RootMenuItem.Index).Items(MenuItem1.Index).Items(MenuItem11.Index).Controls.Add(txEditFile)

  • Peter Peter admin's avatar

    Posted on Feb 19, 2008 (permalink)

    Hi luc,

    In this case, could you please open a support ticket and send us a demo project of the problem?

    Regards,
    Peter
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

  • luc bonenfant avatar

    Posted on Feb 20, 2008 (permalink)

    I upgraded my solution to Prometheus and it resolved my problem !
     Thank you for help.

  • yu li avatar

    Posted on Mar 29, 2011 (permalink)

    I have the same problem,
    May I know how did you fix it.
    Thanks for help

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Menu > Template dynamic creation