“Button”并不包含“CommandName”的定义
<asp:Button ID= "Button1 " runat= "server " Text= "动作1 " CommandName= "踢 " CommandArgument= "足球 " OnClick= "Button_Click " /> <br />
<asp:Button ID= "Button2 " runat= "server " Text= "动作2 " CommandName= "打 " CommandArgument= "篮球 " OnClick= "Button_Click " /> <br />
<hr />
<asp:Label ID= "Label1 " runat= "server " Text= "Label "> </asp:Label>
===============================================================
public 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> ";
}
====================================================================
运行的时候,出现一下错误:
“Button”并不包含“CommandName”的定义
------解决方案--------------------代码运行无问题...
是不是还有其他的控件也注册了这个事件?
------解决方案--------------------Inherits= "myButton "
public partial class myButton : System.Web.UI.Page
{
起名字要考虑一定规矩。
------解决方案--------------------不论其它多少个控件“也注册了这个事件(方法)”,都没有道理导致:“Button”并不包含“CommandName”的定义。