Dynamically created LinkButton not firing any events
Posted
by Brent
on Stack Overflow
See other posts from Stack Overflow
or by Brent
Published on 2010-04-08T09:03:39Z
Indexed on
2010/04/19
6:33 UTC
Read the original article
Hit count: 786
I'm customising the Group Headers on a Telerik RadGrid by injecting a LinkButton into it during the ItemDataBound event. The button renders perfectly, but I can't get it to hit any event handlers.
Here is the code for the button creation:
Private Sub rgWorkRequestItemCosts_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgWorkRequestItemCosts.ItemDataBound
If TypeOf e.Item Is GridGroupHeaderItem Then
Dim oItem As GridGroupHeaderItem = DirectCast(e.Item, GridGroupHeaderItem)
Dim lnkAdd As New LinkButton()
lnkAdd.ID = "lnkAdd"
lnkAdd.CommandName = "CustomAddWorkRequestItemCost"
lnkAdd.CommandArgument = DirectCast(oItem.DataItem, DataRowView).Row("nWorkRequestItemID").ToString()
lnkAdd.Text = String.Format("<img style=""border:0px"" alt="""" width=""12"" src=""{0}"" /> Add new cost", ResolveUrl(String.Format("~/App_Themes/{0}/Grid/AddRecord.gif", Page.Theme)))
lnkAdd.Style("color") = "#000000"
lnkAdd.Style("text-decoration") = "none"
AddHandler lnkAdd.Click, AddressOf lnkAdd_Click
Dim tcPlaceholder As GridTableCell = DirectCast(oItem.Controls(1), GridTableCell)
Dim litText As New LiteralControl(String.Format(" {0}", tcPlaceholder.Text))
tcPlaceholder.Text = String.Empty
tcPlaceholder.Controls.Add(lnkAdd)
tcPlaceholder.Controls.Add(litText)
End If
End Sub
This code explicitly adds a handler for the LinkButton, but that handler is never hit. I've also tried events on the RadGrid (ItemCommand, ItemEvent) but none seem to get hit.
Has anyone got any suggestions of other events to try, or ways to make this work?
Thanks!
© Stack Overflow or respective owner