当前位置: 代码迷 >> ASP.NET >> 出现异常:"Button”并不包含“CommandName”的定义,咋回事,怎么解决
  详细解决方案

出现异常:"Button”并不包含“CommandName”的定义,咋回事,怎么解决

热度:9437   发布时间:2013-02-25 00:00:00.0
出现错误:"Button”并不包含“CommandName”的定义,怎么回事,如何解决
前台代码
HTML code
<asp:Button ID="Button1" CommandName="踢" CommandArgument="足球" runat="server" Text="Button" OnClick="Button_Click" />        <asp:Button id="Button2" CommandName="打" CommandArgument="篮球" Text="动作2" runat="server" OnClick="Button_Click" />

后台代码
C# code
protected void Button_Click(Object sender, EventArgs e)    {        string argName = ((Button)sender).CommandName;        string argArg = ((Button)sender).CommandArgument;        Label1.Text = "您选中的动作为:<font color=red>" + argName + "</font>,动作目标是:<font color=red>" + argArg + "</font>";    }

新手,各位帮忙解决下。

------解决方案--------------------------------------------------------
<asp:Button ID="Button1" CommandName="踢" CommandArgument="足球" runat="server" Text="Button" OnCommand="Button_Command" />
<asp:Button id="Button2" CommandName="打" CommandArgument="篮球" Text="动作2" runat="server" OnCommand="Button_Command" />

protected void Button_Command(object sender, CommandEventArgs e)
{
if(e.CommandName == "踢") //

}
------解决方案--------------------------------------------------------
探讨
<asp:Button ID="Button1" CommandName="踢" CommandArgument="足球" runat="server" Text="Button" OnCommand="Button_Command" />
<asp:Button id="Button2" CommandName="打" CommandArgument="篮球" Text="动作2" runat="server" OnCommand="Button_Command" />

protected void Button_Command(object sender, CommandEventArgs e)
{
if(e.CommandName == "踢") //

}
  相关解决方案