“/HongTianChuan”应用程序中的服务器错误。
--------------------------------------------------------------------------------编译错误 
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 编译器错误消息: CS1061: “Button”不包含“CommandName”的定义,并且找不到可接受类型为“Button”的第一个参数的扩展方法“CommandName”(是否缺少 using 指令或程序集引用?)源错误: 行 24:     protected void Button2_Click(object sender, EventArgs e)
行 25:     {
行 26:         switch (((Button)sender).CommandName.ToString())
行 27:         {
行 28:             case "1":
 源文件: d:\Site\HongTianChuan\Button.aspx.cs    行: 26 
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Button.aspx.cs" Inherits="Button" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:Button ID="Button1" runat="server" Text="按钮的样式会变" 
            onmouseover="c=this.style.backgroundColor;this.style.backgroundColor='#00ff99';this.style.width='350'" 
            onmouseout="this.style.backgroundColor=c;this.style.width='100'"/>
    
    </div>
    <asp:Button ID="Button2" runat="server" CommandName="1" Text="凹凸曼" 
        onclick="Button2_Click" />
    <asp:Button ID="Button3" runat="server" CommandName="c" Text="James" 
        onclick="Button2_Click" />
    <asp:Button ID="Button4" runat="server" CommandName="a" Text="DDATM" 
        onclick="Button2_Click" />
    <p>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </p>
    </form>
</body>
</html>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;public partial class Button : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {    }
    protected void Button1_Click(object sender, EventArgs e)
    {    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        switch (((Button)sender).CommandName.ToString())
        {
            case "1":
                Label1.Text = "James";
                break;
            case "2":
                Label1.Text = "黑大";
                break;
            case "3":
                Label1.Text = "怀念ing";
                break;
        }
    }
}
这是什么问题啊。((Button)sender)后面的CommandName点不出来 求解诶

解决方案 »

  1.   

    button后面本来就没有Commandname
      

  2.   

    <asp:Button ID="Button1" CommandName="a" CommandArgument="aa" runat="server" Text="Button" OnCommand="Button_Command" />
    protected void Button_Command(object sender, CommandEventArgs e)
    {
      if(e.CommandName == "a") }
      

  3.   


    我看天轰穿上面,他是用Button的Click事件做的。而且有((Button)sender).sender
    有人知道怎么弄么?
      

  4.   

    还是没有解决方案啊。。急ING!~