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

2 posts, 0 answers
  1. Aston
    Aston avatar
    3 posts
    Member since:
    Jan 2013

    Posted 07 Feb 2013 Link to this post

    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
        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"
        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"
            Dim Link2 As New LinkButton
            img2.ImageUrl = "\Images\Close_box.png"
            img2.ToolTip = "Delete"
            Dim rtn As RadTreeNode = DirectCast(container, RadTreeNode)
            label1.Text = rtn.Text
            AddHandler label1.DataBinding, AddressOf label1_DataBinding
        End Sub
  2. Boyan Dimitrov
    Boyan Dimitrov avatar
    1968 posts

    Posted 12 Feb 2013 Link to this post


    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 
           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.

    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.
Back to Top