the client side click event is fired firstBtn.Attributes["onclick"] = "javascript:someAction();";

解决方案 »

  1.   

    botton.Attributes["onclick"]="客户脚本"
      

  2.   

    button.attributes.add("onclick","javascript:someevent;"
      

  3.   

    this.Button1.Attributes.Add("OnClick","javascript code");
      

  4.   

    Btn.Attributes["onclick"]="客户端脚本"
      

  5.   

    Button.Attributes.Add("OnClick","code")
    例如Button.Attributes.Add("OnClick","alert('sdfsfsff')")
      

  6.   

    谢谢大家,
    可是当执行client 的javascript后,the button server event is also triggered,why?
      

  7.   

    btn1.Attributes.Add("onclick","return confirm('确定吗?');");
    “是”继续执行server事件,“否”就不执行了。
      

  8.   

    i have tried it,but the server event is still triggered,help!
      

  9.   

    同意思归老大的...
    在代码中(如:page_load中)写入:
    你的按钮.Attributes["onclick"] = "javascript:alert("error");";
      

  10.   

    yes,i have tried as your mention,but the problem is still exist!
      

  11.   


      上面说的都是对的呀,你怎么还不明白呢?
     
      Btn.Attributes["onclick"] = "javascript:someAction();"; 这段代码是写在服务端,
      
      然后在客户端写someAction(); 则点击按钮的时候先触发  客户端someAction()然后在响 应服务端事件
       
      你所说“i have tried it,but the server event is still triggered,help!
    ”如果不想服务器端有事件响应你可以直接使用 html控件  
      

  12.   

    i think the question lie  you lay the code on wrong place,
    you can follow the sample:
    private void Page_Load(object sender, System.EventArgs e)
    {
       //your client trigger
       if(!Page.IsPostBack)
        {
           btn1.Attributes.Add("onclick","return confirm('确定吗?');");
        }
    }
    private void btAdd_Click(object sender, System.EventArgs e)
    {
       //your server code
    }
    remember confirm() writting in the client!