473,406 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

ImageButton Click Event in CustomControl

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
Feb 20 '06 #1
2 2225
DWS
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
"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,
Steve

Feb 20 '06 #2
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/247referenc.../18/94897.aspx

Any thoughts?

Thanks,
Steve

"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

Feb 20 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mark | last post by:
Hi, I am trying to capture the click event of an ImageButton that exists in a composite server control that I am building. I create the imagebutton in the CreateChildControls routine '...
5
by: J McD | last post by:
Hi I have a DataGrid with an ImageButton column. When I click on an imagebutton I get a postback but it doesn't run the OnImgBtnClick method. I can actually comment out the line where I add this...
1
by: Henke | last post by:
Hello, I have one ImageButton controls which I initialize in Page_Load and declare on class level. ImageButton save = new ImageButton(); save.ImageUrl = "save.gif" save.Click += new...
4
by: angus | last post by:
Dear all, I know that i can add a button with oncommand event "ImageButton_Command" by using the asp:ImageButton tag in the aspx code. <asp:ImageButton id="imagebutton1" runat="server"...
3
by: Benjamin Gavin | last post by:
Hi all, I recently stumbled upon a bug in the ASP.NET framework handling of ImageButton based postbacks. The issues derives from the fact that IE and Mozilla handle the case of a missing image...
3
by: TCORDON | last post by:
Why does the click event of an image button that submitts a form does not get fired when ENTER is pressend on a textbox of that form? How can I make this happen? Thanks
13
by: tperri | last post by:
I have an HTML table with several fields like this: <A href="Savings.aspx?category=Food"><asp:imagebutton id="imgFood" ImageUrl="images\buttons\btn-food-i.gif"...
0
by: Oddball | last post by:
I have set up a page with uses two lots of image buttons, one for a collection and one for more images from that collection. I generate all the image buttons on page init (I know, but I...
1
by: serge calderara | last post by:
Dear all, I gave a datagrid object wich has a template column define as follow : <asp:TemplateColumn HeaderText="Evt"> <ItemTemplate> <asp:ImageButton id="ImageButton2" ImageAlign=Middle...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.