e.CommandArgument对于ASP按钮不起作用 [英] e.CommandArgument for asp button is not working

查看:242
本文介绍了e.CommandArgument对于ASP按钮不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发使用C#一个asp.net应用程序。
我创建了一个.aspx页面中,并放置在页面上不同位置的四个按钮。
在服务器端,我想用只需点击一下鼠标事件所有四个按钮。

I am developing a asp.net application using C#. I created an .aspx page and placed four buttons on different locations on the page. On server side, I want to use just one click event for all four buttons.

下面是我的code:

aspx页面

<asp:Button ID="Button1" runat="server" CommandArgument="Button1" onClick = "allbuttons_Click" />
<asp:Button ID="Button2" runat="server" CommandArgument="Button2" onClick = "allbuttons_Click" />
<asp:Button ID="Button3" runat="server" CommandArgument="Button3" onClick = "allbuttons_Click" />
<asp:Button ID="Button4" runat="server" CommandArgument="Button4" onClick = "allbuttons_Click" />

CS页

protected void allbuttons_Click(object sender, EventArgs e)
{
    //Here i want to know which button is pressed
    //e.CommandArgument gives an error
}

您回应将AP preciated。
先谢谢了。

Your response will be appreciated. thanks in advance.

推荐答案

@Tejs是他的意见正确的,看起来像你想是这样的:

@Tejs is correct in his comment, looks like you want something like this:

protected void allbuttons_Click(object sender, EventArgs e)
{
    var argument = ((Button)sender).CommandArgument;
}

这篇关于e.CommandArgument对于ASP按钮不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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