当前位置: 代码迷 >> ASP.NET >> Button.Command的值如何取
  详细解决方案

Button.Command的值如何取

热度:6804   发布时间:2013-02-26 00:00:00.0
Button.Command的值怎么取?
在页面上定义几个按钮
<asp:Button   ID= "Button1 "   runat= "server "   Text= "Button "   CommandName= "b1 "   OnClick= "Button1_Click "   />
<asp:Button   ID= "Button2 "   runat= "server "   CommandName= "b2 "   OnClick= "Button1_Click "   Text= "Button2 "   />


----------------------
        protected   void   Button1_Click(object   sender,   EventArgs   e)
        {
                if   (((System.Web.UI.WebControls.Button)sender.CommandName)== "b1 ")
                {
                        Response.Write( "ss ");
                }
           
        }


-------------
CS0117:   “object”并不包含“CommandName”的定义

为什么呢?
可是我的教程里确实是这么写的呀
哪里出了错误呢?
请个位前辈指教

------解决方案--------------------------------------------------------
protected void Button1_Click(object sender, EventArgs e)
{
if ((((Button)sender).CommandName)== "b1 ")
{
Response.Write( "ss ");
}

}
  相关解决方案