2

I thought this might be easy, but I don't seem to be getting it. I'm working in VB. I'm dynamically creating rows within a table but I wish to add an "EDIT" link/button/event-trigger-of-some-kind that fires a sub, but I need to pass a variable to the sub. The code is as follows. Note the variable that I need to pass is an integer.

Dim CellDescriptionEdit As New TableCell()
RowNameDescription.Cells.Add(CellDescriptionEdit)
CellDescriptionEdit.ID = "CellDescriptionEdit" & UserReader("fldClaimPmtID")
Dim LinkButtonEdit As New LinkButton
LinkButtonEdit.CommandArgument = UserReader("fldClaimPmtID")
LinkButtonEdit.OnClientClick = "LinkButtonEdit_OnClick"
LinkButtonEdit.Text = "EDIT"
CellDescriptionEdit.Controls.Add(LinkButtonEdit)

Then the sub looks like this...

Protected Sub LinkButtonEdit_OnClick(sender As Object, e As EventArgs)
   'Lots of happy code but for example purposes let's use this...        
    lblTest.Text = Int32.Parse(btn.CommandArgument)
End Sub

Any idea how I can get this to work?

1 Answers1

1

To add eventhandlers to your controls you have use the AddHandler statement:

AddHandler LinkButtonEdit.OnClientClick, AddressOf LinkButtonEdit_OnClick

So replace this:

LinkButtonEdit.OnClientClick = "LinkButtonEdit_OnClick"

With the code at the top.


This is also something to consider looking at if you use ASP.NET: Dynamically Added DropDownlists Are Not Firing SelectedIndexChanged Event

Community
  • 1
  • 1
Visual Vincent
  • 18,045
  • 5
  • 28
  • 75