Raising Event of dynamically created Button in ITemplate to the Parent Menu

2 posts, 0 answers
  1. Support
    Support avatar
    7 posts
    Member since:
    Apr 2010

    Posted 27 Jan 2015 Link to this post

    I have been trying to figure out how to get the Click event of a button that  is created in an ITemplate for a menu item to bubble up to the top menu item layer.

    I have a multi layer menu (for an intranet site, multiple top level and children/children layers)

    Within one, I have created a 2nd generation child that spawns another child that has a custom template the adds a text box and a button for a quick entry method.

     MAIN MENU / IT / DO SOMETHING / (iTemplate Textbox + Button)

    What I need is to be able to (hopefully) to capture the event at the menu item click event to handle the event in the same page and not in the ITemplate (I am able to intercept the click event in the ITemplate class)

    The Menu Item Createion is a follows:

    Dim _JobLines As New RadMenuItem
    _JobLines.Text = "Clear Job Lines"

    .Add(_JobLines) ' Adds to the parent menu

    Dim _JobLinesTextBox As New RadMenuItem ' This is the menu item with the custom ITemplate instantiation
    Dim _template As New Custom_Rad_Templates.TextBoxTemplate()


    ITemplate Class:

    Class TextBoxTemplate
    Implements ITemplate

    Public Event Go_Click(sender As Object, e As EventArgs)

    Public Sub InstantiateIn(ByVal container As Control)
    Dim txtEntry As New TextBox()
    txtEntry.ID = "txtEntry"
    Dim cmdGo As New Button
    cmdGo.ID = "cmdGo"
    cmdGo.Text = "Go"

    AddHandler cmdGo.Click, AddressOf cmdGo_Click

    End Sub

    Public Sub cmdGo_Click(sender As Object, e As EventArgs)

             RaiseEvent Go_Click(Me, e) ' (This is where I lose the event)
    End Sub

    Public Sub InstantiateIn1(container As Control) Implements ITemplate.InstantiateIn

    End Sub
    End Class

    Im sure this has been done before, just cant find any clear help on the issue.

  2. Boyan Dimitrov
    Boyan Dimitrov avatar
    1728 posts

    Posted 30 Jan 2015 Link to this post


    As far as I understand you want to access the RadMenuItem instance from the Button Click event handler.

    An easy way to do that is:
         1. To cast the sender object to the appropriate object (Button in your case as shown below) .
    public void cmdGo_Click(object sender, EventArgs e)
            Dim target As Button= DirectCast(sender, Button)

         2. The associated RadMenuItem is returned by the property NamingContainer.
    Dim item As RadMenuItem = DirectCast(target.BindingContainer, RadMenuItem)

    Boyan Dimitrov

    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.

  3. DevCraft R3 2016 release webinar banner
Back to Top