• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
我的学习笔记
   首页       联系   管理    订阅  订阅

按钮-Button

按钮添加JaveScript代码 12onmouseover="c=this.style.backgroundColor; this.style.backgroundColor='#00ff99'; this.style.width='150';" 3onmouseout="this.style.backgroundColor=c;this.style.width='93';" Font-Bold="true"/

按钮添加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;
        }


    }
posted @ 2007-12-15 20:43  吴有鋆  阅读(198)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3