如何找出页面中点击的按钮 [英] how to find out the which button is clicked in page

查看:106
本文介绍了如何找出页面中点击的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的页面中有三个链接按钮是否会生成每个基于按钮的报告,我想知道如何找出在正常按钮事件中点击了哪个链接按钮



< br $> b $ b

请与我分享任何想法

解决方案

有两种方法。



1.为所有链接按钮定义单独的点击事件,如'Rohan Leuva'建议

2.提供命令参数带有如下所述的链接按钮:



ASPX:

 <   asp:LinkBut​​ton     runat   =  server    ID   =  link1    OnClick   =  Lnk_Click    CommandArgument   =  1   文字  =  test Link 1 >  <   / asp :LinkBut​​ton  >  
< asp:LinkBut​​ton runat = server ID < span class =code-keyword> = link2 OnClick = Lnk_Click CommandArgument = 2 文字 = 测试链接2 > < / asp:LinkBut​​ton >
< asp:LinkBut​​ton runat = server ID = link3 OnClick = Lnk_Click CommandArgument = 3 文字 = test Link 3 > < / asp:LinkBut​​ton >





代码背后:

 受保护  void  Lnk_Click(  object  sender,EventArgs e)
{
var button =(LinkBut​​ton)sender ;
var commandArgument = button.CommandArgument;

if (commandArgument == 1
{
// 链接按钮1单击
}
else if (commandArgument == 2
{
// 链接按钮2单击
}
else if (commandArgument == 3
{
// 链接按钮3点击
}
}


In my page three linkbuttons are there each button based report will be generated and i want to how to find out which linkbutton is clicked in normal button event



please share any idea to me

解决方案

There are two ways.

1. Define separate click events for all the link buttons as 'Rohan Leuva' suggested
2. Provide Command Argument with link button as mentioned below :

ASPX :

<asp:LinkButton runat="server" ID="link1" OnClick="Lnk_Click" CommandArgument="1" Text="test Link 1"></asp:LinkButton>
        <asp:LinkButton runat="server" ID="link2" OnClick="Lnk_Click" CommandArgument="2" Text="test Link 2"></asp:LinkButton>
        <asp:LinkButton runat="server" ID="link3" OnClick="Lnk_Click" CommandArgument="3" Text="test Link 3"></asp:LinkButton>



Code Behind:

protected void Lnk_Click(object sender, EventArgs e)
      {
          var button = (LinkButton)sender;
          var commandArgument = button.CommandArgument;

          if (commandArgument == "1")
          {
              // Link Button 1 Clicked
          }
          else if (commandArgument == "2")
          {
              // Link Button 2 Clicked
          }
          else if (commandArgument == "3")
          {
              // Link Button 3 Clicked
          }
      }


这篇关于如何找出页面中点击的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆