I have the code snippet below. I fill a table of imagebuttons and would
like to know which one was clicked to trigger the post back. Unfortunately,
the Command event does not fire unless I load the images on the load_page
event. Since I want to load the table of images based on the click event
from another control, and only based on feedback from some controls do I
even display the image list, I thought I could trap the command or click
event, but I can not.
Any ideas? Thanks in advance.
Protected WithEvents img As System.Web.UI.WebControls.ImageButton
Public Sub GoItem(ByVal sender As System.Object, ByVal e As
System.Web.UI.WebControls.CommandEventArgs) Handles img.Command
Response.Write("<script language=javascript>window.alert('Image1 was
commanded with commandarg = " & sender.CommandArgument & "')</script>")
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
' IF I LOAD IT HERE IT WORKS OF COURS - FillImages(10, 0)
End Sub
Private Sub btnFillTable_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnFillTable.Click
' ----------------- HERE ID DOES NOT
FillImages(10, 100)
End Sub
Public Sub FillImages(ByVal image_count As Integer, ByVal start_value As
Integer)
Dim tr As System.Web.UI.WebControls.TableRow
Dim td As System.Web.UI.WebControls.TableCell
Dim img As New System.Web.UI.WebControls.ImageButton
Dim i As Integer
Table1.Rows.Clear()
For i = 1 To 10
tr = New System.Web.UI.WebControls.TableRow
td = New System.Web.UI.WebControls.TableCell
img = New ImageButton
img.ID = "img" & "_" & i.ToString()
img.ImageUrl = "images/small_note.gif"
img.CommandName = "Contact" & i
img.CommandArgument = i + start_value
AddHandler img.Command, AddressOf GoItem
img.EnableViewState = False
td.Controls.Add(img)
tr.Cells.Add(td)
Table1.Rows.Add(tr)
Next
End Sub
'End Sub