日期:2014-05-17  浏览次数:20452 次

出现错误:"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 == "踢") //

}