| | |
ImageButton Command Event
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2006
Posts: 47
Reputation:
Solved Threads: 0
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:
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:
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 •
•
Join Date: Jul 2006
Posts: 47
Reputation:
Solved Threads: 0
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
The lines
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? •
•
Join Date: Mar 2009
Posts: 2
Reputation:
Solved Threads: 0
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 :
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...
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 :
ASP.NET Syntax (Toggle Plain Text)
Protected Sub Gerak(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) MsgBox("Masuk", MsgBoxStyle.OkOnly) End Sub For i = 0 To jum - 1 img(i) = New ImageButton() AddHandler img(i).Click, AddressOf Me.Gerak img(i).ImageUrl() = "images/kodok-hijau.gif" pGame.Controls.Add(img(i)) 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.
![]() |
Similar Threads
- Small issue re: ModalPopupExtender - not firing ImageButton.Click event (ASP.NET)
- Where are the Command and Conquer saved game files? (Windows NT / 2000 / XP)
- Vending (Drinking) Machine Java Code (Java)
- Setting the command buttons Forecolor (Visual Basic 4 / 5 / 6)
- Three New Command-Line Tools (Windows tips 'n' tweaks)
Other Threads in the ASP.NET Forum
- Previous Thread: Problem in LogIn
- Next Thread: raise event handler for image button
| Thread Tools | Search this Thread |
.net 2.0 activexcontrol advice ajax alltypeofvideos asp asp.net bc30451 bottomasp.net browser businesslogiclayer button c# c#gridviewcolumn checkbox click commonfunctions compatible confirmationcodegeneration content contenttype courier css dataaccesslayer database datagridview datagridviewcheckbox datalist deadlock development dgv dropdownlist dropdownmenu dynamically edit expose fill flash flv formatdecimal forms formview gridview homeedition iframe iis javascript jquery listbox login menu microsoft mono mouse mssql multistepregistration news numerical objects opera order panelmasterpagebuttoncontrols radio ratings registration reportemail rotatepage save schoolproject search security serializesmo.table silverlight smartcard smoobjects software sql-server sqlserver2005 suse textbox tracking unauthorized validation vb.net video videos virtualdirectory vista visual-studio visualstudio web webapplications webarchitecture webdevelopemnt webprogramming webservice xml xsl youareanotmemberofthedebuggerusers





