找到单击了哪个Linkbutton [英] Find which Linkbutton was clicked
本文介绍了找到单击了哪个Linkbutton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的页面上有3个链接按钮。
如何确定在服务器端点击了哪个链接按钮。
如果我有一个列表框然后我可以轻松找到{if listbox.selectedindex == 1}这样做;
我怎么知道最后点击了哪个链接按钮。?
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.?
推荐答案
我给出了实现目标的一小步。
步骤1:在.aspx页面上定义三个链接按钮但这三个具有相同的onclick
事件,所以你的.aspx页面是:
I am giving few step to achieve the goal.
Step 1.: Define three link buttons on .aspx page but these three have sameonclick
event so your .aspx page is :
<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>
步骤2:现在 onclick
事件定义在页面后面的代码和此事件 sender
分配给 LinkButton
,用于标识单击的按钮。让我们看看这个事件
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
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");
}
}
参考 LinkButton.OnClick方法 [ ^ ]。
你必须为每个LinkButton
提及OnClick =LinkButton_Click
,其中LinkButton_Click
是服务器端事件名称,在事件中你可以检查点击了哪个LinkButton
。
Refer LinkButton.OnClick Method[^].
You have to mentionOnClick="LinkButton_Click"
for eachLinkButton
, whereLinkButton_Click
is the Server side Event name and inside the Event you can check whichLinkButton
Is clicked.
>
这篇关于找到单击了哪个Linkbutton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文