获取点击了哪个链接按钮
我正在开发 ASP.NET/C# 应用程序。
我有这样的链接按钮
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="Link_Click">Link1</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" OnClick="Link_Click">Link2<Chart</asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="server" OnClick="Link_Click">Link3</asp:LinkButton>
有没有办法知道在 Link_Click 事件中单击了哪一个?
我不想为每个链接创建不同的事件。
我正在寻找这样的东西:
protected void Link_Click(object sender, EventArgs e)
{
string LinkClicked = Get_Which_Link_Has_Been_Clicked();
if(LinkClicked == "Link1")
{
//DoSomething;
}
else if(LinkClicked == "Link2")
{
//Do something else;
}
//and so on;
}
提前致谢。
I am working on an ASP.NET/C# Application.
I have Link buttons like this
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="Link_Click">Link1</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" OnClick="Link_Click">Link2<Chart</asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="server" OnClick="Link_Click">Link3</asp:LinkButton>
Is there a way to know which one was clicked in the Link_Click event?
I don't want to create a different event for each link.
I am looking for something like this:
protected void Link_Click(object sender, EventArgs e)
{
string LinkClicked = Get_Which_Link_Has_Been_Clicked();
if(LinkClicked == "Link1")
{
//DoSomething;
}
else if(LinkClicked == "Link2")
{
//Do something else;
}
//and so on;
}
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将传递给函数的
sender
值转换为 LinkButton,然后从中获取 id -Try casting the
sender
value passed to the function to a LinkButton then getting the id from that -