Link to home
Start Free TrialLog in
Avatar of sexyrexy
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?
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Example from my code:

  AddHandler linkName.LinkClicked, AddressOf ChartLinkClicked

  Private Sub ChartLinkClicked(ByVal sender As Object, ByVal e As LinkLabelLinkClickedEventArgs)

  End Sub 'ChartLinkClicked'

Bob

Avatar of sexyrexy
sexyrexy

ASKER

That's the same code as I am using, except you're using a LinkLabel, so the eventargs is slightly different.
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
Avatar of OzzMod
OzzMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial