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

How do I trap the click event of a link control in a RadNodeTemplate

1 Answer 44 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Aston
Top achievements
Rank 1
Aston asked on 07 Feb 2013, 04:03 PM
How do I trap the click event of a link control in a RadNodeTemplate. The node is created in code seen below.
    Public Sub TreeInit()
 
       Dim newNode2 As New AttachmentFolderNode("FolderNode")
 
        Dim tvNodes As Telerik.Web.UI.RadTreeNodeCollection = RadTreeView1.Nodes
        tvNodes.Add(newNode2)
 
 
        RadTreeView1.DataBind()
 
    End Sub
 
Public Class AttachmentFolderNode
    Inherits RadTreeNode
    Dim tp As New AttachmentFolderNodeTemplate
    Public Sub New(nodeText As String)
        MyBase.Text = nodeText
        MyBase.ImageUrl = ".\Images\book.png"
        tp.InstantiateIn(Me)
    End Sub
End Class
 
Public Class AttachmentFolderNodeTemplate
    Implements System.Web.UI.ITemplate
 
    Public Overridable Sub InstantiateIn(container As Control) Implements ITemplate.InstantiateIn
 
        Dim img1 As New Image
        Dim img2 As New Image
        Dim lbl_space1 As New Label
        Dim lbl_space2 As New Label
 
        lbl_space1.Text = " "
        lbl_space2.Text = " "
 
        Dim label1 As New Label
        img1.ImageUrl = ".\Images\Close_Box.png"
        img2.ImageUrl = ".\Images\edit.png"
 
        Dim Link1 As New LinkButton
        img1.ImageUrl = ".\Images\edit.png"
        img1.ToolTip = "Edit"
        Link1.Controls.Add(img1)
 
        Dim Link2 As New LinkButton
        img2.ImageUrl = "\Images\Close_box.png"
        img2.ToolTip = "Delete"
        Link2.Controls.Add(img2)
 
 
        Dim rtn As RadTreeNode = DirectCast(container, RadTreeNode)
        label1.Text = rtn.Text
        AddHandler label1.DataBinding, AddressOf label1_DataBinding
        container.Controls.Add(label1)
        container.Controls.Add(lbl_space1)
        container.Controls.Add(Link1)
        container.Controls.Add(lbl_space2)
        container.Controls.Add(Link2)
 
    End Sub

1 Answer, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 12 Feb 2013, 12:03 PM
Hello,

An easy and convenient way to catch a click event from a control in your template would be to add a handler in the code behind for that specific control. In the code snippet below you could find a demonstration of creating a link button control and attach its click event to a specific handler. This way you can implement the desired behavior when user clicks on that link button.
//code behind

Public Sub InstantiateIn(container As Control)
           Dim Link1 As New LinkButton
           Link1.Text = "link button"
           AddHandler Link1.Click, AddressOf Link1_Click 
           container.Controls.Add(Link1)
       End Sub
Private Sub Link1_Click(sender As Object, e As EventArgs)
            'here goes you custom logic
           Dim link As LinkButton = DirectCast(sender, LinkButton)
           link.Text = "Clicked"
       End Sub

Here you may find more information about adding templates to the RadTreeView control at runtime.

Regards,
Boyan Dimitrov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
TreeView
Asked by
Aston
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Share this question
or