By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,805 Members | 1,100 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,805 IT Pros & Developers. It's quick & easy.

Same event handler for multiple link buttons

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
yes It did work! Thank a lot

Feb 6 '06 #3

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.