按钮添加JaveScript代码
<
asp:Button
ID
=”Button1″
runat
=”server”
Height
=”28px”
Text
=”点我”
Width
=”93px”
2
onmouseover
=”c=this.style.backgroundColor; this.style.backgroundColor=’#00ff99′; this.style.width=’150′;”
3
onmouseout
=”this.style.backgroundColor=c;this.style.width=’93’;”
Font-Bold
=”true”
/>
按钮添加属性
protected
void
Button2_Load(
object
sender, EventArgs e)
{
Button2.Attributes.Add(“onmouseover“, “c=this.style.backgroundColor;this.style.backgroundColor=’#00ff99′;“);
Button2.Attributes.Add(“onmouseout“, “this.style.backgroundColor=c“);
Button2.Text = DateTime.Now.ToString();
}
按钮CommandName属性
PS:三个按钮同时触发button2_Click事件,根据事件惩罚者((Button)sender)的CommandName来判断
<
asp:Button
ID
=”Button2″
runat
=”server”
CommandName
=”a”
OnClick
=”Button2_Click”
Text
=”小明”
OnLoad
=”Button2_Load”
/>
<
asp:Button
ID
=”Button3″
runat
=”server”
CommandName
=”b”
OnClick
=”Button2_Click”
Text
=”小里”
/>
<
asp:Button
ID
=”Button4″
runat
=”server”
CommandName
=”c”
OnClick
=”Button2_Click”
Text
=”小王”
/>
protected
void
Button2_Click(
object
sender, EventArgs e)
{
switch (((Button)sender).CommandName)
{
case “a“:
lb1.Text = ((Button)sender).Text;
break;
case “b“:
lb1.Text = ((Button)sender).Text;
break;
default:
lb1.Text = “33333“;
break;
}
}
转载于:https://www.cnblogs.com/net123/archive/2007/12/15/996215.html
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/111060.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...