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

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

1 Answer 110 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Support
Top achievements
Rank 1
Support asked on 27 Jan 2015, 07:04 PM
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()
_template.InstantiateIn(_JobLinesTextBox)

_JobLines.Items.Add(_JobLinesTextBox)

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
container.Controls.Add(txtEntry)
container.Controls.Add(cmdGo)

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.

Thanks

1 Answer, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 30 Jan 2015, 02:42 PM
Hello,

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) .
      //vb
     
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.
//vb
Dim item As RadMenuItem = DirectCast(target.BindingContainer, RadMenuItem)



Regards,
Boyan Dimitrov
Telerik
 

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.

 
Tags
Menu
Asked by
Support
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Share this question
or