Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to bind a tree in horizontal manner upto 2 levels
for that i am using 15 static link buttons
when i click on any link button then i need to display tree of that particular user.


I want to implement same functionality for those 15 different linkbutton click events.

Is it possible to implement it without writing 15 click events in code behind
Posted

paste ur code inside a user defined function and call it in all linkbutton click event
 
Share this answer
 
Comments
P.Salini 10-Sep-11 3:26am    
Thanks for your reply devbtl
i knew this one
is there any other effective way
An Event is simply a delegate pointing to a Method that handles it (there might be a bit more to it, but this part is important). This makes it possible to have multiple Events point (or listen) to the same Method.
Take for instance the following code in VB:
VB
AddHandler LinkLabel1.Click, AddressOf LinkLabel_Click
AddHandler LinkLabel2.Click, AddressOf LinkLabel_Click
AddHandler LinkLabel3.Click, AddressOf LinkLabel_Click

Private Sub LinkLabel_Click(ByVal sender As Object, ByVal e As EventArgs)
   ' Your code here, get the LinkLabel that was clicked by casting the sender.
End Sub

This is similiar to the following code in C#
C#
LinkLabel1.Click += LinkLabel_Click;
LinkLabel2.Click += LinkLabel_Click;
LinkLabel3.Click += LinkLabel_Click;

private void LinkLabel_Click(Object sender, EventArgs e){
   // Your code here, get the LinkLabel that was clicked by casting the sender.
}

Alternatively, in VB, you could use the Handles keyword like follows:
VB
Private Sub LinkLabel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles LinkLabel1.Click, LinkLabel2.Click, LinkLabel3.Click
   ' Your code here, get the LinkLabel that was clicked by casting the sender.
End Sub

I have never worked with ASP.NET, but I am pretty sure this works the same way :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900