473,799 Members | 3,298 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Same event handler for multiple link buttons

I create link buttons dynamically in the code and give them IDs through
which I can distinguish them.I want to know how to create a single
event handler for all the link buttons that I create The event handler
should also be able to identify which link button was clicked....(I am
using VB as the code behind language). Please reply....

Feb 3 '06 #1
3 6255
Hi Akshay,

When you create the controls, add an event handler that points to the common
routine. Here's a little demo. This is for ASP.NET 2.0.

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]

<%@ Page Language="VB" %>
<script runat="server">
Protected Sub Page_Load _
(ByVal sender As Object, _
ByVal e As System.EventArg s)
Dim lnkbutton1 As New LinkButton
lnkbutton1.ID = "LinkButton 1"
lnkbutton1.Text = "LinkButton 1"
Dim lnkbutton2 As New LinkButton
lnkbutton2.ID = "LinkButton 2"
lnkbutton2.Text = "LinkButton 2"
Dim lit As New Literal
lit.Text = "<br />"
Dim evnthandler As New _
EventHandler(Ad dressOf Me.LinkButton_H andler)
AddHandler lnkbutton1.Clic k, evnthandler
AddHandler lnkbutton2.Clic k, evnthandler
PlaceHolder1.Co ntrols.Add(lnkb utton1)
PlaceHolder1.Co ntrols.Add(lit)
PlaceHolder1.Co ntrols.Add(lnkb utton2)
End Sub

Protected Sub LinkButton_Hand ler _
(ByVal sender As Object, _
ByVal e As System.EventArg s)
Dim lnkbtn As LinkButton
lnkbtn = sender
Response.Write( lnkbtn.ID)
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>LinkButt on_Handler</title>
</head>
<body>
<form id="form1" runat="server">
<asp:placeholde r id="PlaceHolder 1" runat="server"> </asp:placeholder >
</form>
</body>
</html>
"akki" <ak************ *@gmail.com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
I create link buttons dynamically in the code and give them IDs through
which I can distinguish them.I want to know how to create a single
event handler for all the link buttons that I create The event handler
should also be able to identify which link button was clicked....(I am
using VB as the code behind language). Please reply....

Feb 3 '06 #2
yes It did work! Thank a lot

Feb 6 '06 #3
Great! Thanks for reporting back.

"akki" <ak************ *@gmail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
yes It did work! Thank a lot

Feb 6 '06 #4

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

Similar topics

2
3714
by: Linda | last post by:
Hi, How do I dynamically add linkbuttons and wire them to same event? I am able to add linkbuttons but they do not fire the event. Does anybody have a working sample? Many thanks, Linda
2
3428
by: Keith Smith | last post by:
Is there a way to attach event handler code to multiple controls?
5
1715
by: Russell Smallwood | last post by:
Hello all, Why can't I wire up an event during the "Raise PostBackEvent" stage of a postback? Just in case this is the wrong question, the situation: deep in the bowls of some code-behind loop: ImageButton A is created (with ID "A"). ImageButton A's click event is
3
1934
by: Peter Vermilye | last post by:
How can I dynamically create buttons and wire them to an event handler? I have seen how I can add buttons to an event handler that are pre-created as part of the codebehind using AddHandler, but I can't use AddHandler with a button that is created locally, nor can I seem to create multiple button objects and add them to the page using a button object that exists outside the procedure I am using.... thus: Protected WithEvents...
2
3878
by: mark | last post by:
Is there a means of raising an event when ANY button on a windows application form is clicked wherein the actual button clicked can be determined in the generic click events code (eg by way of interogating the sender)? -- mark
3
4377
by: m00nm0nkey | last post by:
Hello I have very recently moved from VS2003/ASP.Net 1.1 to VS2005/ASP.Net 2.0. I have made up a web page which has many labels, image buttons and link buttons. I am have a lot of trouble writing an event handler for a particular link button and I have no idea why. This is exactly what I am doing, step by step: 1. Add a link button to the form using the designer. Set control name as
6
2276
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 the same method (aka delegate?). I use the Tag property within this method to determine what user action is taking place. Very simple: When adding toolbar button: tbButton.Click += new...
4
2141
by: eggie5 | last post by:
I have this even handler (using prototype.js): showCommentsLinks.observe('click', function(event) { alert('hi') }); It's attaching to a link element: <a id="showCommentsLink" href="comments/">Show Comments</a>
9
11933
by: lilOlMe | last post by:
Hi there! I have generated a GridView that looks something like: SportName| CompanyNameX |CompanyNameY |CompanyNameZ Hockey.....| Shipping------------ |Accounting-------- |Shipping------------ BaseBall...| Receiving-----------|Shipping------------|Accounting--------- Etc............| Accounting----------|Receiving---------- |Receiving----------- Where there are an unknown number of Company Names and an unknown number of Sport...
0
9546
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10490
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10260
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9078
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7570
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4146
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.