Click here to Skip to main content
15,885,705 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a 3 link buttons on my page.
How can i determine which link button was clicked on server side.
Like if i have a listbox then i can find that easily with {if listbox.selectedindex == 1}do this;
How can i know which link button was last clicked.?
Posted
Comments
Karthik_Mahalingam 16-Jan-14 21:57pm    
post your code..

I am giving few step to achieve the goal.

Step 1.: Define three link buttons on .aspx page but these three have same onclick event so your .aspx page is :

HTML
<div>

    <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">LinkButton1</asp:LinkButton>

    <asp:LinkButton ID="LinkButton2" runat="server" onclick="LinkButton1_Click">LinkButton2</asp:LinkButton>

    <asp:LinkButton ID="LinkButton3" runat="server" onclick="LinkButton1_Click">LinkButton3</asp:LinkButton>
    </div>


Step 2: Now onclick event define on code behind page and in this event sender assign to a LinkButton that identifies which button clicked. Lets see this event

C#
protected void LinkButton1_Click(object sender, EventArgs e)
        {
            LinkButton lnkButton = (LinkButton) sender;
            if (lnkButton.ID == "LinkButton1")
            {
                Response.Write("Button First clicked");
            }
            else if (lnkButton.ID == "LinkButton2")
            {
                Response.Write("Button second clicked");
            }
            else
            {
                Response.Write("Button third clicked");
            }
        }
 
Share this answer
 
Comments
Ankur\m/ 16-Jan-14 22:42pm    
Correct, Control's Id property should be used. 5!
Sandeep Singh Shekhawat 16-Jan-14 22:58pm    
Thanks Dear Ankur
Karthik_Mahalingam 16-Jan-14 22:59pm    
5! Good
Sandeep Singh Shekhawat 16-Jan-14 22:59pm    
Thanks Karthik
Rockstar_ 17-Jan-14 6:22am    
yes my 5!
Refer LinkButton.OnClick Method[^].

You have to mention OnClick="LinkButton_Click" for each LinkButton, where LinkButton_Click is the Server side Event name and inside the Event you can check which LinkButton Is clicked.
 
Share this answer
 
v3
Comments
Ankur\m/ 16-Jan-14 22:41pm    
It doesn't need to be different. All link buttons can have same click event.
Yes you are right. I am updating it. Sorry. :)
Karthik_Mahalingam 16-Jan-14 23:12pm    
TD,
4!!, because Sandeep solution is much better..
Oh yes, at night in a hurry. My mistake. As I was worried about my health tests. :)

Check Coming to Hyderabad for my Health Checkup
Karthik_Mahalingam 17-Jan-14 6:48am    
Its ok, NP..
Health is first.. these all next priority...
5 for cheering you up from your health issue :)
Take care ....

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