sexyrexy
asked on
Dynamic linkbutton not triggering event
I have a series of LinkButtons that are generated in a for loop:
...
Dim myLink As New LinkButton
myLink.Text = "[Edit]"
myLink.CommandName = "Jump"
myLink.CommandArgument = dtrReader("stepID")
myLink.ID = "lbtnEdit_st" + intStep.ToString()
AddHandler myLink.Click, AddressOf Edit_Click
phInputTables.Controls.Add (myLink)
...
When I click the LinkButton, Edit_Click does not run. The page posts back but the specified event sub is never triggered... how do I get the LinkButton to trigger the event handler?
...
Dim myLink As New LinkButton
myLink.Text = "[Edit]"
myLink.CommandName = "Jump"
myLink.CommandArgument = dtrReader("stepID")
myLink.ID = "lbtnEdit_st" + intStep.ToString()
AddHandler myLink.Click, AddressOf Edit_Click
phInputTables.Controls.Add
...
When I click the LinkButton, Edit_Click does not run. The page posts back but the specified event sub is never triggered... how do I get the LinkButton to trigger the event handler?
ASKER
That's the same code as I am using, except you're using a LinkLabel, so the eventargs is slightly different.
ASKER
OK, I figured it out. The sub that added the events in the first place wasn't called on postback, so the events weren't re-added when the controls were dynamically built the second time around.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
AddHandler linkName.LinkClicked, AddressOf ChartLinkClicked
Private Sub ChartLinkClicked(ByVal sender As Object, ByVal e As LinkLabelLinkClickedEventA
End Sub 'ChartLinkClicked'
Bob