468,738 Members | 2,559 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,738 developers. It's quick & easy.

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 1049
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

24 posts views Thread by el_roachmeister | last post: by
4 posts views Thread by tshad | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.