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

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 6238
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.EventArgs)
Dim lnkbutton1 As New LinkButton
lnkbutton1.ID = "LinkButton1"
lnkbutton1.Text = "LinkButton1"
Dim lnkbutton2 As New LinkButton
lnkbutton2.ID = "LinkButton2"
lnkbutton2.Text = "LinkButton2"
Dim lit As New Literal
lit.Text = "<br />"
Dim evnthandler As New _
EventHandler(AddressOf Me.LinkButton_Handler)
AddHandler lnkbutton1.Click, evnthandler
AddHandler lnkbutton2.Click, evnthandler
PlaceHolder1.Controls.Add(lnkbutton1)
PlaceHolder1.Controls.Add(lit)
PlaceHolder1.Controls.Add(lnkbutton2)
End Sub

Protected Sub LinkButton_Handler _
(ByVal sender As Object, _
ByVal e As System.EventArgs)
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>LinkButton_Handler</title>
</head>
<body>
<form id="form1" runat="server">
<asp:placeholder id="PlaceHolder1" runat="server"></asp:placeholder>
</form>
</body>
</html>
"akki" <ak*************@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.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.googlegr oups.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
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
by: Keith Smith | last post by:
Is there a way to attach event handler code to multiple controls?
5
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...
3
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...
2
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...
3
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...
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: 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"...
9
by: lilOlMe | last post by:
Hi there! I have generated a GridView that looks something like: SportName| CompanyNameX |CompanyNameY |CompanyNameZ Hockey.....| Shipping------------ |Accounting-------- |Shipping------------...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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...

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.