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

Adding usercontrol as a Tool in the Toolbar

2 Answers 42 Views
ToolBar
This is a migrated thread and some comments may be shown as answers.
Amarjyoti
Top achievements
Rank 1
Amarjyoti asked on 10 Aug 2010, 05:43 AM
Hi,

I am trying to add a web user control(.ascx) in the RAD Toolbar. But the toolbar is not showing the user control. Can you please guide me where am i going wrong.

Following is  my code snippet:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim paths() As String
        'Dim TaggerTemplate As TaggerTemplate

        Dim tlbBtn As RadToolBarButton
        tlbBtn = New RadToolBarButton("Tagger")
        tlbBtn.ItemTemplate = New TaggerTemplate()
        RadFileExplorer1.ToolBar.Items.Add(tlbBtn)

        'TaggerTemplate = New TaggerTemplate
        'Dim item As RadToolBarItem = tlbBtn
        'TaggerTemplate.InstantiateIn(item)
        'item.ItemTemplate = New TaggerTemplate()

        'RadFileExplorer1.ToolBar.DataBind()

    End Sub



Public Class TaggerTemplate
    Implements ITemplate


    Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
        Dim tagger As CtrlTagger

        tagger = New CtrlTagger
        tagger.ID = "TagItem"
        ' container.Controls.Add(tagger)


        Dim wrapperDiv As HtmlGenericControl = New HtmlGenericControl("DIV")
        wrapperDiv.Controls.Add(tagger)
        container.Controls.Add(wrapperDiv)
    End Sub


End Class

2 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 12 Aug 2010, 12:52 PM
Hello Amarjyoti,

You should use LoadControl method to add a user control, also the button should be added only on the first page load:

If Not Page.IsPostBack Then
   Dim tlbBtn As RadToolBarButton
   tlbBtn = New RadToolBarButton("Tagger")
   RadFileExplorer1.ToolBar.Items.Add(tlbBtn)
End If
 
Dim tagger As Control = LoadControl("test2.ascx")
RadFileExplorer1.ToolBar.FindItemByText("Tagger").Controls.Add(tagger)


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
0
Amarjyoti
Top achievements
Rank 1
answered on 14 Aug 2010, 10:14 AM
Thanks Yana, it solved my problem.
Tags
ToolBar
Asked by
Amarjyoti
Top achievements
Rank 1
Answers by
Yana
Telerik team
Amarjyoti
Top achievements
Rank 1
Share this question
or