后台代码!
protected void Button1_Command(object sender, CommandEventArgs e)
{
switch (e.CommandName)
{
case "a":
Response.Write("<script>alert('你点击了button1!')</script>");
break;
case "b":
Response.Write("<script>alert('你点击了button2!')</script>");
break;
case "c":
Response.Write("<script>alert('你点击了button3!')</script>");
break;
default:
Response.Write("<script>alert('wrong!')</script>");
break;
}
}
前台代码!
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<br />
<asp:Button ID="Button1" runat="server" CommandArgument="a" CommandName="a" OnClick="Page_Load"
OnCommand="Button1_Command" Text="Button1" />
<asp:Button ID="Button2" runat="server" CommandName="b" Text="Button2" CommandArgument="b" />
<asp:Button ID="Button3" runat="server" CommandName="c" Text="Button3" CommandArgument="c" /></div>
</form>
</body>
</html>这个是为什么啊!为什么只有button1 有效果button2和button3没有效果啊!
protected void Button1_Command(object sender, CommandEventArgs e)
{
switch (e.CommandName)
{
case "a":
Response.Write("<script>alert('你点击了button1!')</script>");
break;
case "b":
Response.Write("<script>alert('你点击了button2!')</script>");
break;
case "c":
Response.Write("<script>alert('你点击了button3!')</script>");
break;
default:
Response.Write("<script>alert('wrong!')</script>");
break;
}
}
前台代码!
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<br />
<asp:Button ID="Button1" runat="server" CommandArgument="a" CommandName="a" OnClick="Page_Load"
OnCommand="Button1_Command" Text="Button1" />
<asp:Button ID="Button2" runat="server" CommandName="b" Text="Button2" CommandArgument="b" />
<asp:Button ID="Button3" runat="server" CommandName="c" Text="Button3" CommandArgument="c" /></div>
</form>
</body>
</html>这个是为什么啊!为什么只有button1 有效果button2和button3没有效果啊!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货