button其实不算新了,都是绝对的老面孔了,呵呵!但是既然是做系列实例,当然就要做完整撒,虽然不完美也是美,但是我们设想所有人都只有一个胳膊的话,那维纳斯都会变味了,呵呵!!
前台HTML代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>
最常规的用法===》按纽事件撒!!<br />
<br />
<asp:Button ID="Button4" runat="server" OnClick="Button4_Click" Text="按我" />
<asp:Label ID="Label1" runat="server"></asp:Label><br />
<br />
==================================================================<br />
<br />
鼠标触发改变按纽字体:这里需要注意的是,在添加mouse事件的时候VS会给你警告,但是你可以不管他(哈哈,VS也有见识短的时候,挖哈哈)<br />
<br />
<asp:Button ID="Button1" runat="server" Text="天轰穿系列" Width="169px" onmouseover="c=this.style.backgroundColor;this.style.backgroundColor='#00ff99'" onmouseout="this.style.backgroundColor=c" />
注意看源里面,下面这个代码是重点 onmouseover="c=this.style.backgroundColor;this.style.backgroundColor='#00ff99'"
onmouseout="this.style.backgroundColor=c"
<br />
<br />
<asp:Button ID="Button2" runat="server" Text="变粗给大家看" onmouseover="this.style.fontWeight='bold'" onmouseout="this.style.fontWeight='normal'" />
下面是主要控制JS语句<br />
onmouseover="this.style.fontWeight='bold'" onmouseout="this.style.fontWeight='normal'"<br />
<br />
===================================================================<br />
<br />
下面主要是演示 <strong>CommandName </strong>,这个是什么意思我不知道,软件说叫 发泡,主要是几个不同名字,不同命令名的按纽,响应同一事件,但是又要区别开到底是那一个按纽触发了该事件!!<br />
<br />
要多个按纽触发同一事件的话只需要在 选中按纽--属性--事件--Click后面选择要触发的那个即可,但是别忘记给每个按纽的 CommandName 取上不同的名字哟!!<br />
<br />
<asp:Button ID="Button3" runat="server" CommandName="a" OnClick="Button3_Click" Text="川哥" />
<asp:Button ID="Button5" runat="server" CommandName="b" OnClick="Button3_Click" Text="梅姐" />
<asp:Button ID="Button6" runat="server" CommandName="c" OnClick="Button3_Click" Text="小皓文" /><br />
<br />
<asp:Label ID="Label2" runat="server" Font-Bold="True" Font-Names="隶书" Font-Size="X-Large" ForeColor="Red"></asp:Label>
<asp:Label ID="Label3" runat="server" Text="干了坏事,抓住!"></asp:Label><br />
<br />
<br />
</div>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>
最常规的用法===》按纽事件撒!!<br />
<br />
<asp:Button ID="Button4" runat="server" OnClick="Button4_Click" Text="按我" />
<asp:Label ID="Label1" runat="server"></asp:Label><br />
<br />
==================================================================<br />
<br />
鼠标触发改变按纽字体:这里需要注意的是,在添加mouse事件的时候VS会给你警告,但是你可以不管他(哈哈,VS也有见识短的时候,挖哈哈)<br />
<br />
<asp:Button ID="Button1" runat="server" Text="天轰穿系列" Width="169px" onmouseover="c=this.style.backgroundColor;this.style.backgroundColor='#00ff99'" onmouseout="this.style.backgroundColor=c" />
注意看源里面,下面这个代码是重点 onmouseover="c=this.style.backgroundColor;this.style.backgroundColor='#00ff99'"
onmouseout="this.style.backgroundColor=c"
<br />
<br />
<asp:Button ID="Button2" runat="server" Text="变粗给大家看" onmouseover="this.style.fontWeight='bold'" onmouseout="this.style.fontWeight='normal'" />
下面是主要控制JS语句<br />
onmouseover="this.style.fontWeight='bold'" onmouseout="this.style.fontWeight='normal'"<br />
<br />
===================================================================<br />
<br />
下面主要是演示 <strong>CommandName </strong>,这个是什么意思我不知道,软件说叫 发泡,主要是几个不同名字,不同命令名的按纽,响应同一事件,但是又要区别开到底是那一个按纽触发了该事件!!<br />
<br />
要多个按纽触发同一事件的话只需要在 选中按纽--属性--事件--Click后面选择要触发的那个即可,但是别忘记给每个按纽的 CommandName 取上不同的名字哟!!<br />
<br />
<asp:Button ID="Button3" runat="server" CommandName="a" OnClick="Button3_Click" Text="川哥" />
<asp:Button ID="Button5" runat="server" CommandName="b" OnClick="Button3_Click" Text="梅姐" />
<asp:Button ID="Button6" runat="server" CommandName="c" OnClick="Button3_Click" Text="小皓文" /><br />
<br />
<asp:Label ID="Label2" runat="server" Font-Bold="True" Font-Names="隶书" Font-Size="X-Large" ForeColor="Red"></asp:Label>
<asp:Label ID="Label3" runat="server" Text="干了坏事,抓住!"></asp:Label><br />
<br />
<br />
</div>
</form>
</body>
</html>
后台CS代码
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button4_Click(object sender, EventArgs e)
{
Label1.Text = "你有本事哦,敢按前面那家伙,我都不敢想哦!";
}
protected void Button3_Click(object sender, EventArgs e)
{//这里三个按纽都是触发的这一个事件,
switch (((Button)sender).CommandName)//获取他的命令名,进入循环判断
{
case "a":
Label2.Text = "天轰穿";
break;
case "b":
Label2.Text = "川哥的媳妇";
break;
default:
Label2.Text = "川哥的儿子";
break;
}
}
}
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button4_Click(object sender, EventArgs e)
{
Label1.Text = "你有本事哦,敢按前面那家伙,我都不敢想哦!";
}
protected void Button3_Click(object sender, EventArgs e)
{//这里三个按纽都是触发的这一个事件,
switch (((Button)sender).CommandName)//获取他的命令名,进入循环判断
{
case "a":
Label2.Text = "天轰穿";
break;
case "b":
Label2.Text = "川哥的媳妇";
break;
default:
Label2.Text = "川哥的儿子";
break;
}
}
}