net123

按钮添加JaveScript代码

1<asp:Button ID="Button1" runat="server" Height="28px" Text="点我" Width="93px"
2onmouseover="c=this.style.backgroundColor; this.style.backgroundColor=\'#00ff99\'; this.style.width=\'150\';"
3onmouseout="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="小里" />&nbsp;
        
<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;
        }


    }

分类:

技术点:

相关文章: