473,385 Members | 1,769 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,385 software developers and data experts.

How to identify event sender......

Hi all,
I have problem........ I have array of buttons and I want to call one
common event service. But I need to know the index of clicked button -- how
can I do that?

thanks
jakub
Nov 15 '05 #1
3 23823
Ok, I knew there was an easier (less code) way to do this...

Basically create your handler function like so:

private void ButtonHandler(object sender, System.EventArgs e) {

MessageBox.Show(sender.ToString());

}

Then, For each button you can select the Events in the Properties box and
change the Click event to point to your ButtonHandler function.
---
John Wiese
---
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"John Wiese [MS]" <jw****@online.microsoft.com> wrote in message
news:#e**************@TK2MSFTNGP11.phx.gbl...
Jakub,

You could write your own function that takes the same parameter (sender, e) as the btn_click funcitons, then in your btn_click simply call your function passing along the input parameters you got. This would allow your handler
function to use sender.ToString() to determine which button was clicked.

John Wiese

--
This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"Jakub Otahal" <jo*****@ftvs.cuni.cz> wrote in message
news:ue**************@TK2MSFTNGP11.phx.gbl...
Hi all,
I have problem........ I have array of buttons and I want to call one
common event service. But I need to know the index of clicked button --

how
can I do that?

thanks
jakub


Nov 15 '05 #2
Hi,

You can use the sender parameter of the handler to see what control sent
the event, if you have your controls in an array it would be something like:

protected void handler( object o, EventArgs e ){

int index = 0;
foreach( Control control in controlArray)
{
if ( sender == control )
break;
index++;
}
}

hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Jakub Otahal" <jo*****@ftvs.cuni.cz> wrote in message
news:ue**************@TK2MSFTNGP11.phx.gbl...
Hi all,
I have problem........ I have array of buttons and I want to call one
common event service. But I need to know the index of clicked button -- how can I do that?

thanks
jakub

Nov 15 '05 #3
"Jakub Otahal" <jo*****@ftvs.cuni.cz> wrote in message
news:ue**************@TK2MSFTNGP11.phx.gbl...
Hi all,
I have problem........ I have array of buttons and I want to call one
common event service. But I need to know the index of clicked button -- how can I do that?


The button itself is being passed as "sender," but if you really need it's
index you can save it in buttons "Tag" property.
Nov 15 '05 #4

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

Similar topics

7
by: Amadelle | last post by:
Hi all and thanks in advance, I am stuck! I can't figure out how to identify which button was clicked on my ASP.NET page in the PostBack event? So what I am trying to do is to is to have an if...
17
by: Alphonse Giambrone | last post by:
I am building a web app for users to add/edit data. They may add/edit several records during a session. When they are done (not necessarily immediately, could be 10 or more minutes later), I need...
5
by: Joey G | last post by:
How do I get the name or identify the control that caused the page postback. I need the information during page init. Reason why, because I need to tell usercontrol_1 that usercontrol_2 button was...
7
by: Grahmmer | last post by:
I have a few timers that are added to a form at runtime. I can handle the event fine, but I cannot identify which timer fired. Is there a way to do this? Timer Creation: -------------...
13
by: Charles Law | last post by:
Mr "yEaH rIgHt" posted the following link about a week ago in answer to my question about removing event handlers. > http://www.vbinfozine.com/t_bindevt.shtml Following on from that post, the...
4
by: Reny J Joseph Thuthikattu | last post by:
Hi, I want to do some validation on the Value change of a Datagrid column.Can any one tell how do i do it? Regards Reny
4
by: Me | last post by:
My form has a dynamically populated context menu, and each has the same event handler for the click event. The event need to write the text of the clicked menu item into a database, so I need to...
2
by: Bry | last post by:
I have a context menu which is shared between a TreeView and ListView control (both controls show the same information, similar to how Windows Explorer works, so it makes sense to use the same menu...
1
by: Jim McGivney | last post by:
In VWD I have a webpage that contains a number of ImageButtons. Each ImageButton has a unique CommandName (e.g. IB1, IB2, etc). I can tell which ImageButton has been pressed by testing for the...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.