ImageButton Command Event

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2006
Posts: 47
Reputation: ChimpusDupus is an unknown quantity at this point 
Solved Threads: 0
ChimpusDupus ChimpusDupus is offline Offline
Light Poster

ImageButton Command Event

 
0
  #1
Jul 10th, 2006
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("&nbsp; &nbsp;"))
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 47
Reputation: ChimpusDupus is an unknown quantity at this point 
Solved Threads: 0
ChimpusDupus ChimpusDupus is offline Offline
Light Poster

Re: ImageButton Command Event

 
0
  #2
Jul 11th, 2006
Anyone?
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 47
Reputation: ChimpusDupus is an unknown quantity at this point 
Solved Threads: 0
ChimpusDupus ChimpusDupus is offline Offline
Light Poster

Re: ImageButton Command Event

 
0
  #3
Jul 12th, 2006
Looks like I cannot get the imagebutton's _click event to happen either
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 47
Reputation: ChimpusDupus is an unknown quantity at this point 
Solved Threads: 0
ChimpusDupus ChimpusDupus is offline Offline
Light Poster

Re: ImageButton Command Event

 
0
  #4
Jul 12th, 2006
Okay, I've broken this down to make the problem as clear as I can. Here is the code I have written for a simple page with one table called Table1(with one row and one cell), and a Button called Button1


PartialClass _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Sub imgClick(ByVal sender As Object, ByVal e As ImageClickEventArgs)
Response.Write("Image Click")
End Sub
Sub imgCommand(ByVal sender As Object, ByVal e As CommandEventArgs)
Response.Write("Image Command")
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim img As New ImageButton
img.ImageUrl = "~/t_can.gif"
AddHandler img.Click, AddressOf Me.imgClick
AddHandler img.Command, AddressOf Me.imgCommand
Table1.Rows(0).Cells(0).Controls.Add(img)
End Sub
EndClass

The lines AddHandler img.Click, AddressOf Me.imgClick and AddHandler img.Command, AddressOf Me.imgCommand add the events for the image button. When this code is done to an image button that is either already on the form, or is generated during the Form_Load event, this works correctly and the actions in the imgClick and imgCommand subs are executed when the image is clicked; however, if the button is generated by another event such as a button's click event, this does not work. Why does this happen and how might I be able to fix it?
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 2
Reputation: tybalt88 is an unknown quantity at this point 
Solved Threads: 0
tybalt88 tybalt88 is offline Offline
Newbie Poster

Re: ImageButton Command Event

 
0
  #5
Mar 27th, 2009
hi chimpus dupus...
i have same problem with u...
n i have posting in many forum n no one can resolve it... OMG...
the problem is just simple as you say...
i create imagebutton n it's click event...
but when i click the imagebutton, the event not getting called...

my code is :

  1. Protected Sub Gerak(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
  2. MsgBox("Masuk", MsgBoxStyle.OkOnly)
  3. End Sub
  4.  
  5.  
  6. For i = 0 To jum - 1
  7. img(i) = New ImageButton()
  8. AddHandler img(i).Click, AddressOf Me.Gerak
  9. img(i).ImageUrl() = "images/kodok-hijau.gif"
  10. pGame.Controls.Add(img(i))
  11. Next

when i click imagebutton, it won't show the messagebox....

maybe you can try using button... my friend tell me that she use button with the same method and work...
Last edited by peter_budo; Mar 27th, 2009 at 3:35 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC