Hi,
I am creating a page in which thumnails, in the form of Image Buttons (System.Web.UI.WebControls.ImageButton), are dynamically created based on which LinkButton is clicked out of a group of several links. I need each thumbnail to generate a full-size image on the page when clicked. I would use the ImageButton_Click event, but I need arguments other than X and Y positions. So I decided to use the _Command event, which is described (just as the _Click event) to fire when the button is clicked. This event gives me a CommandName and a CommandArgument to work with; however, it will not work. I have put both break points and a response.write() into the _Command event's stub and nothing occurs to indicate that it runs, though the _Click event does occur. My code is below:
Sub showThumbs(ByVal sender As Object, ByVal e As CommandEventArgs)
Dim a As Integer = 0
Do
tblEvents.Rows(a).BackColor = Drawing.Color.White
tblEvents.Rows(a + 1).BackColor = Drawing.Color.LightBlue
a += 2
On Error Resume Next
Loop While a < RowNum
tblEvents.Rows(e.CommandName).BackColor = Drawing.Color.Aquamarine
tblEvents.Rows(e.CommandName).ID = "Selected"
Dim Conn As New Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("sysObjDBConnectionString").ConnectionString)
Dim Cmd As New Data.SqlClient.SqlCommand("SELECT event_photo_id FROM EVENT_PHOTO WHERE event_id =" & e.CommandArgument, Conn)
Dim EventRead As Data.SqlClient.SqlDataReader
Conn.Open()
EventRead = Cmd.ExecuteReader
Dim Thumb As ImageButton
Dim TR As TableRow
Dim TC As TableCell
Dim x As Integer = 0
Dim y As Integer = 0
While EventRead.Read
x += 1
If x = 4 Then x = 1
If x = 1 Then
y += 1
If y = 3 Then y = 1
TR = New TableRow
If y = 1 Then
TR.BackColor = Drawing.Color.White
Else
TR.BackColor = Drawing.Color.LightBlue
End If
End If
TC = New TableCell
TCThumbInit.Visible = False 'hide initial information
Thumb = New ImageButton
Thumb.CommandArgument = e.CommandArgument
Thumb.CommandName = e.CommandName
AddHandler Thumb.Command, AddressOf Me.showFull
Thumb.ImageUrl = "~/IMG.aspx?Type=2&ID=" & EventRead(0)
Thumb.Width = "100"
TC.Controls.Add(Thumb)
TC.Controls.Add(New LiteralControl(" "))
TR.Cells.Add(TC)
If x = 3 Then tblThumb.Rows.Add(TR)
End While
If x <> 3 Then tblThumb.Rows.Add(TR)
Conn.Close()
End Sub
Sub showFull(ByVal sender As Object, ByVal e As CommandEventArgs)
'showThumbs(sender, e)
Response.Write("imageButton.Command")
'Dim FullIMG As New Image
'FullIMG.ImageUrl = "~/IMG.aspx?Type=2&ID=" & e.CommandArgument
'TCFull.controls.add(FullIMG)
End Sub
The showThumb() sub procedure is called as the LinkButton_Command event and the ShowFull() sub is assigned to the ImageButton_Command event in the line: AddHandler Thumb.Command, AddressOf Me.showFull