ImageButton Click Event in CustomControl

G

Guest

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,
Steve
 
G

Guest

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top