Dynamic linkbutton not triggering event

Posted on 2005-03-21
Medium Priority
Last Modified: 2009-07-29
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

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?
Question by:sexyrexy
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 96

Expert Comment

by:Bob Learned
ID: 13592335
Example from my code:

  AddHandler linkName.LinkClicked, AddressOf ChartLinkClicked

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

  End Sub 'ChartLinkClicked'



Author Comment

ID: 13592367
That's the same code as I am using, except you're using a LinkLabel, so the eventargs is slightly different.

Author Comment

ID: 13592546
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.

Accepted Solution

OzzMod earned 0 total points
ID: 13629312
Closed, 200 points refunded.
Community Support Moderator (Graveyard shift)

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question