Steve,
Search for "handles", "withevents", "commandargument", "commandname"
Three simple steps to wire up custom buttons
1. the control is declared withevents in the class that will receive the
event.
Private WithEvents btn1 As New Button
2. The control is added to the controls collection
Me.Controls.Add(btn1)
3. Use the handles keyword on the sub
Protected Sub Click1(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles btn1.Click
....do something cool
End Sub
Good Luck
DWS
[quoted text, click to view] "Steve" wrote:
> Hi,
> I have a dynamically created ImageButton in a custom control, and I can't
> get the control to handle the ImageButton Click event. I see the control in
> the Page.Request.Form.AllKeys collection, but it's represented as "imgbtn.X"
> (and .Y), and I'm guessing that .NET can't connect the name to the event
> since the ID isn't an exact match. I read an article stating that I need to
> use IPostBackDataHandler methods, but I didn't have a lot of luck. Can
> someone tell me what I'm missing here?
>
> Also, I'd be willing to override whatever event/method is appropriate and
> wire-up the event handler myself, but I wasn't sure what to override. If
> someone could point me in the right direction, I'd appreciate it.
>
> TIA,
Thanks for the input, DWS. As it happens, I'm working in C# (but I know VB
and follow the code below just fine), and I already have the C# equivalent of
everything below. I have a variety of other dynamically created controls
that are working (LinkButtons, Buttons, etc, firing/handling events w/
commandname/commandargument successfully), only the ImageButtons are failing.
I'm wondering if my problem is somehow related to this:
http://www.dotnet247.com/247reference/msgs/18/94897.aspx Any thoughts?
Thanks,
Steve
[quoted text, click to view] "DWS" wrote:
> Steve,
>
> Search for "handles", "withevents", "commandargument", "commandname"
>
> Three simple steps to wire up custom buttons
> 1. the control is declared withevents in the class that will receive the
> event.
> Private WithEvents btn1 As New Button
> 2. The control is added to the controls collection
> Me.Controls.Add(btn1)
> 3. Use the handles keyword on the sub
> Protected Sub Click1(ByVal sender As Object, ByVal e As System.EventArgs) _
> Handles btn1.Click
> ...do something cool
> End Sub
>
> Good Luck
> DWS
>
Don't see what you're looking for? Try a search.