473,320 Members | 2,104 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,320 software developers and data experts.

Same method for different buttons

I have a group of buttons.
When the user clicks on a button I'd like to execute
same code. Every button should send its caption to that method.
How can I do that?
Nov 18 '05 #1
4 1100
Mark, I don't fully understand what you are trying to do. Each button has 1
method that can hook into it's Click event...multiple buttons can share the
same click event. Inside the click event, you can access all buttons. What
do you mean by "send its caption to that method"? As opposed to sending
information into a method, you should make the method get the information.
At worst case, you can recursively loop through the Page.Controls and all
child controls and check if the control IS a button.

Karl

"Mark Goldin" <ma********@comcast.net> wrote in message
news:O9**************@TK2MSFTNGP09.phx.gbl...
I have a group of buttons.
When the user clicks on a button I'd like to execute
same code. Every button should send its caption to that method.
How can I do that?

Nov 18 '05 #2
"Mark Goldin" <ma********@comcast.net> wrote in news:O9cz14JiEHA.1656
@TK2MSFTNGP09.phx.gbl:
I have a group of buttons.
When the user clicks on a button I'd like to execute
same code. Every button should send its caption to that method.
How can I do that?


Just assign all buttons the same Event Handler.

Or change the Handles keyword to handle all the buttons.click

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 18 '05 #3
Hi Mark,

You can have multiple events assigned to a common subroutine by listing the
events after the Handles clause

Private Sub MyButtonHandler _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click, _
Button2.Click, Button3.Click

Ken
Microsoft MVP [ASP.NET]

"Mark Goldin" <ma********@comcast.net> wrote in message
news:O9**************@TK2MSFTNGP09.phx.gbl...
I have a group of buttons.
When the user clicks on a button I'd like to execute
same code. Every button should send its caption to that method.
How can I do that?


Nov 18 '05 #4
side note:
Instead of checking for the button's "caption" (text) you might want to the
the CommandName property instead. Its not necessarily any better or worse,
but its a little more in alignment with other similar scenarios (e.g.
handling events for templated controls)
"Mark Goldin" <ma********@comcast.net> wrote in message
news:O9**************@TK2MSFTNGP09.phx.gbl...
I have a group of buttons.
When the user clicks on a button I'd like to execute
same code. Every button should send its caption to that method.
How can I do that?

Nov 18 '05 #5

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

Similar topics

24
by: el_roachmeister | last post by:
Is there a way to make a text link post to a form without passing all the parameters in the url? The urls tend to get very long and messy. I often wonder if there is a limit to how long they can...
2
by: Jeff | last post by:
I'm trying to create a dynamic form that can have multiple groups of radio buttons (each group has two buttons) with the same name. Essentially, the form allows a user to enter as many names as...
5
by: Colleyville Alan | last post by:
I have a sub that can do two different tasks based on the value of one variable. So I'd like to have two different buttons on the same form run this, but each one setting a flag so that the...
1
by: Chuck | last post by:
I appreciate any help!!! I have an application that has 4 different forms that display the same information except for the fact that they are fed from 4 different parameter queries. The 4...
5
by: Girish | last post by:
I have TWO submit buttons of type IMAGE on my asp form. This renders as <input type="image">. I need to be able to eble the ENTER button for both buttons. Yes, I know that for the input type...
2
by: Pete | last post by:
Hi all... I sincerly hope one of the MS guys can clear this up for me... First some background... Ok, I have a web site which is fully translatable into several languages. All the strings...
6
by: Joseph Geretz | last post by:
Writing an Outlook AddIn with C#. For the user interface within Outlook I'm adding matching pairs of Toolbar buttons and Menu items. All of the buttons and menu items are wired up to send events to...
4
by: tshad | last post by:
I have a function that I want to jump to from 2 different controls (ImageButton and LinkButton). The problem is I get the error: Method 'Public Sub PrintPage_Click(sender As Object, e As...
3
by: Michael.Suarez | last post by:
I have 1 contextmenu with several buttons. two different listviews sit beside each other on the same form. Both use the same context menu. I have a method for when a menu item gets clicked: ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.