本文介绍了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按钮不起作用
发布评论