e.CommandArgument对于ASP按钮不起作用

编程入门 行业动态 更新时间:2024-10-13 10:30:40
本文介绍了e.CommandArgument对于ASP按钮不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I am developing a asp 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按钮不起作用

本文发布于:2023-11-23 01:16:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619586.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按钮   不起作用   CommandArgument   ASP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!