Button

前台代码

<asp:Button ID="btn_1" runat="server" Text="按钮_1" CommandName="btn1" oncommand="btn_commond" CommandArgument="show1" />    
<asp:Button ID="btn_2" runat="server" Text="按钮_2" CommandName="btn2" oncommand="btn_commond" CommandArgument="show2" />

后台代码

   protected void btn_commond(object sender, CommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "btn1":
                    Response.Write("当前点击的是第一个按钮"+"&nbsp");
                    show(e.CommandArgument);
                    break;
                case "btn2":
                    Response.Write("当前点击的是第二个按钮"+"&nbsp");
                    show(e.CommandArgument);
                    break;
            }
        }

        protected void show(object commond)
        {
            Response.Write("你点击的对象是"+commond.ToString());
        }

这个上面的东西要注意的是没有按钮的点击事件,所以要在前台按钮的属性事件中加一个oncommand="btn_commond"

谁有更好的实现方式期待共享!

 

posted @ 2010-11-05 20:34  Curitis  阅读(183)  评论(0编辑  收藏  举报