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

multiple link buttons for one sub question

I have about 20 link buttons that i need handled by one sub. I don't want to
have 20 onClick_xxx subs or onCommand subs.
I'm not having much luck calling a single sub for all the button or figuring
out which button caused the event?
I'm sure this is a simple one for most of you.
thanks
kes
--
I figure if you can''t ask a question honestly, even if it suggests
blasphemy and disturbs the sensibilities of the grand masters of programming
you should quite and join a cult. kes
Nov 19 '05 #1
4 1581
What have you tried. Basically, the LinkButton would just call an event
handler, right? Could you not have all event hanlders point to the same
method?

"WebBuilder451" <We***********@discussions.microsoft.com> wrote in message
news:D5**********************************@microsof t.com...
I have about 20 link buttons that i need handled by one sub. I don't want to have 20 onClick_xxx subs or onCommand subs.
I'm not having much luck calling a single sub for all the button or figuring out which button caused the event?
I'm sure this is a simple one for most of you.
thanks
kes
--
I figure if you can''t ask a question honestly, even if it suggests
blasphemy and disturbs the sensibilities of the grand masters of programming you should quite and join a cult. kes

Nov 19 '05 #2
Define your event handler to match the signature for System.EventHandler.
Specify that your sub will handle the click event for each of your buttons.
CType() sender to LinkButton and retrieve the ID or the Text (if you haven't
defined an ID for each button). Use if blocks or select case to perform the
processing specific to a particular button.

example (sorry if my VB syntax is a little off):
protected sub linkButton_Click(Sender as Object, e as EventArgs)
if Not (Sender is LinkButton)
return

Dim lb as LinkButton = CType(Sender, LinkButton)
if lb.ID = "Button1" Then
'Processing for Button1
elseif lb.ID = "Button2" Then
'Processing for Button2
end if

' Any other code
end sub

If your linkbuttons are defined at design time, you could also just compare
sender to each linkbutton:

if Sender.Equals(Button1) Then
' Processing for button 1
elseif Sender.Equals(Button2) Then
' Processing for button 2
end if

HTH
----
http://www.davefancher.com
"WebBuilder451" wrote:
I have about 20 link buttons that i need handled by one sub. I don't want to
have 20 onClick_xxx subs or onCommand subs.
I'm not having much luck calling a single sub for all the button or figuring
out which button caused the event?
I'm sure this is a simple one for most of you.
thanks
kes
--
I figure if you can''t ask a question honestly, even if it suggests
blasphemy and disturbs the sensibilities of the grand masters of programming
you should quite and join a cult. kes

Nov 19 '05 #3
Thanks for responding,
i can get the on click to go to a single sub, but i can't get the name of
the linkbutton that caused the event.
example
<TD class="md"><asp:linkbutton id="cc4" OnClick="cc_onClick"
runat="server">04</asp:linkbutton></TD>
<TD class="md"><asp:linkbutton id="cc5" OnClick="cc_onClick"
runat="server">05</asp:linkbutton></TD>

will each call :
Sub cc_onClick(ByVal sender As Object, ByVal e As EventArgs) Handles
Me.lblDiag1.Text = "ok"
End Sub
But i'd like to get some information from the link button like ID, command
argues, or what ever...
thanks
kes

--
I figure if you can''t ask a question honestly, even if it suggests
blasphemy and disturbs the sensibilities of the grand masters of programming
you should quite and join a cult. kes
"Peter Rilling" wrote:
What have you tried. Basically, the LinkButton would just call an event
handler, right? Could you not have all event hanlders point to the same
method?

"WebBuilder451" <We***********@discussions.microsoft.com> wrote in message
news:D5**********************************@microsof t.com...
I have about 20 link buttons that i need handled by one sub. I don't want

to
have 20 onClick_xxx subs or onCommand subs.
I'm not having much luck calling a single sub for all the button or

figuring
out which button caused the event?
I'm sure this is a simple one for most of you.
thanks
kes
--
I figure if you can''t ask a question honestly, even if it suggests
blasphemy and disturbs the sensibilities of the grand masters of

programming
you should quite and join a cult. kes


Nov 19 '05 #4
That was it!
Thanks
IOU1
kes
--
I figure if you can''t ask a question honestly, even if it suggests
blasphemy and disturbs the sensibilities of the grand masters of programming
you should quite and join a cult. kes
"Dave Fancher" wrote:
Define your event handler to match the signature for System.EventHandler.
Specify that your sub will handle the click event for each of your buttons.
CType() sender to LinkButton and retrieve the ID or the Text (if you haven't
defined an ID for each button). Use if blocks or select case to perform the
processing specific to a particular button.

example (sorry if my VB syntax is a little off):
protected sub linkButton_Click(Sender as Object, e as EventArgs)
if Not (Sender is LinkButton)
return

Dim lb as LinkButton = CType(Sender, LinkButton)
if lb.ID = "Button1" Then
'Processing for Button1
elseif lb.ID = "Button2" Then
'Processing for Button2
end if

' Any other code
end sub

If your linkbuttons are defined at design time, you could also just compare
sender to each linkbutton:

if Sender.Equals(Button1) Then
' Processing for button 1
elseif Sender.Equals(Button2) Then
' Processing for button 2
end if

HTH
----
http://www.davefancher.com
"WebBuilder451" wrote:
I have about 20 link buttons that i need handled by one sub. I don't want to
have 20 onClick_xxx subs or onCommand subs.
I'm not having much luck calling a single sub for all the button or figuring
out which button caused the event?
I'm sure this is a simple one for most of you.
thanks
kes
--
I figure if you can''t ask a question honestly, even if it suggests
blasphemy and disturbs the sensibilities of the grand masters of programming
you should quite and join a cult. kes

Nov 19 '05 #5

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

Similar topics

3
by: Chris Barker | last post by:
Hi all, We've been having a discussion over on the wxPython-users mailing list about how to deal with multiple versions of wxPython. During the discussion it came up that this isn't a problem...
3
by: rachel | last post by:
Hi all, I am new in ASP.Net. I have a question on link multiple web forms together. Here is the scenario: I create an Index.aspx WebForm which consists of a banner and three navigator...
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...
2
by: D | last post by:
Most of my web forms have multiple buttons (Proceed, Back, link buttons for various screens, etc.) It looks like, say a required field validator for example, gives me an error message no matter...
8
by: TJS | last post by:
what are folks doing to get around limitation of one server form per page ?
1
by: brian | last post by:
'visual studio 2002 pro 1.0 framwork' I am creating dynamic Link buttons on my intranet site and assigning a click_event to them. A user clicks a link and I call the method to recreate the...
9
by: Gummy | last post by:
Hello, I created a user control that has a ListBox and a RadioButtonList (and other stuff). The idea is that I put the user control on the ASPX page multiple times and each user control will...
3
by: Nico | last post by:
I have an idea but don't know if it's possible, from a technical point of view. Imagine to have some text. Example "John and Mary go to the cinema." I'd like to have this kind of links. By...
4
by: CURTISLESPERANCE | last post by:
Hi, I am trying to figure out if this is possible. I need to display 4 radio buttons next to a question then 3 radio buttons after. The 2 different group radio buttons and questions are coming from...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.