OK, this may very well be a dumb question (I do very little ASP coding), but here goes:
I have a web user control. Initially it has one control, an image button, that is the "background" of the control. The containing page can add "items" to the control (the "item" is defined by a class within the control) and when an item is added, the control creates a new ImageButton object to represent the newly added item.
Now, what I need to do is to wire up the Click event of the newly added ImageButton. I can catch the Click event of the initial (background) image button (in this case, using AddHandler syntax) with no problem; however, I can't seem to find a way to capture the event of the dynamically added item(s).
A few more details:
I declare two private variables of type ImageButton WithEvents - one for the background and another to represent the dynamically added imagebuttons, e.g.
When an item is added by the containing page, we create a New instance of imgIcon and hook up the handler, e.g.
The newly added image buttons have a z-index of 1+ the z-index of the background. However, I can't catch the Click event of the imgIcon objects, and when they're clicked, since they are "above" the background, the background Click event clearly doesn't fire either. I've also tried adding the dynamically created ImageButtons as children of the background imagebutton (in the above code, they're added to the usercontrol.controls collection directly). I've seen some mention of bubbling events, but have found no way to use that in this case. Fundamentally, I just want the (x,y) mouse coordinates..... :-(
Two stars to anyone that can help me wire up this event....
Thanks in advance.
"I swear by my life and my love of it that I will never live for the sake of another man, nor ask another man to live for mine."
— John Galt
Atlas Shrugged
If you want to get the best response to a question, please check out FAQ222-2244 first
I have a web user control. Initially it has one control, an image button, that is the "background" of the control. The containing page can add "items" to the control (the "item" is defined by a class within the control) and when an item is added, the control creates a new ImageButton object to represent the newly added item.
Now, what I need to do is to wire up the Click event of the newly added ImageButton. I can catch the Click event of the initial (background) image button (in this case, using AddHandler syntax) with no problem; however, I can't seem to find a way to capture the event of the dynamically added item(s).
A few more details:
I declare two private variables of type ImageButton WithEvents - one for the background and another to represent the dynamically added imagebuttons, e.g.
Code:
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Drawing
<DefaultProperty("Text"), ToolboxData("<{0}:MyControl runat=server></{0}:MyControl")> _
Public Class MyControl
Inherits System.Web.UI.WebControls.WebControl
Private WithEvents img As System.Web.UI.WebControls.ImageButton = New System.Web.UI.WebControls.ImageButton
Private WithEvents imgIcon As System.Web.UI.WebControls.ImageButton
... then, on Init
With img
...set some display properties, etc.
End With
Me.Controls.Add(img)
AddHandler img.Click, AddressOf IconClick
When an item is added by the containing page, we create a New instance of imgIcon and hook up the handler, e.g.
Code:
imgIcon = New System.Web.UI.WebControls.ImageButton
With imgIcon
... set display properties, etc.
End With
Me.Controls.Add(imgIcon)
AddHandler imgIcon.Click, AddressOf IconClick
The newly added image buttons have a z-index of 1+ the z-index of the background. However, I can't catch the Click event of the imgIcon objects, and when they're clicked, since they are "above" the background, the background Click event clearly doesn't fire either. I've also tried adding the dynamically created ImageButtons as children of the background imagebutton (in the above code, they're added to the usercontrol.controls collection directly). I've seen some mention of bubbling events, but have found no way to use that in this case. Fundamentally, I just want the (x,y) mouse coordinates..... :-(
Two stars to anyone that can help me wire up this event....
Thanks in advance.
"I swear by my life and my love of it that I will never live for the sake of another man, nor ask another man to live for mine."
— John Galt
Atlas Shrugged
If you want to get the best response to a question, please check out FAQ222-2244 first