[thelist] ASP.NET Adding a linkbutton programmatically

Peter Brunone (EasyListBox.com) peter at easylistbox.com
Mon Aug 7 16:35:18 CDT 2006

				   What if you change the assignment slightly like this:

AddHandler lbAlpha.Click, New EventHandler(AddressOf lbAlpha_Click)

   Does that help?

   By the way, you should be able to assign the event handler in your original way... as long as you use the reference to the sub itself.  Also, you might want to make that sub shared instead of private... not sure if that will do much, but it's worth a shot... and remove the "ByVal" designators, since I'm pretty sure the default behavior for objects is ByRef.

   Once you're inside the sub, you can access the linkbutton by ID and gather property values... or just use the Sender parameter, since that is a reference to the object (linkbutton) that triggered the event.



						From: "Casey Crookston"  

						caseyc at IntelliSoftmn.com 

Thanks for the help, Peter. I'm not using any javasscript other then
what is genrated by the LinkButton. Here's what I've got so far.... the
problem seems to be getting Private Sub lbAlpha_Click to fire, and once
it does, how to glean the letter that was clicked.


Private Sub lbCategory_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles lbCategory.Click
trAlpha.Visible = True
trButton.Visible = False
End Sub

Private Sub populateAlpha()
Dim i As Integer
For i = 65 To 90
Dim lbAlpha As LinkButton = New LinkButton
lbAlpha.Text = "&#" & i & "; "
lbAlpha.CssClass = "alpha_link"
lbAlpha.ID = "lbAlpha" & i
'lbAlpha.Attributes.Add("OnClick", "lbAlpha_Click()")
AddHandler lbAlpha.Click, AddressOf lbAlpha_Click
End Sub

Private Sub lbAlpha_Click(ByVal sender As Object, ByVal e As
trAlpha.Visible = True
trButton.Visible = False
lblTest.Text = "Hey There!"
End Sub

More information about the thelist mailing list