你在button前加一个textbox,把textbox的宽和高都设置0,这样你的button就能吸收到回车了

解决方案 »

  1.   

    // .aspx
    <asp:textbox id=txtUserName ...
    <asp:textbox id=txtPassword textmode=password ...
    <asp:button id=btnLogin onclick=btnLogin_Click  ...// .aspx.cs
    protected void btnLogin_Click(object sender, EventArgs e) {
        bool login = CheckLogin(txtUserName.Text, txtPassword.Text);
        if(login)  { //... }
        else { //... }
    }bool CheckLogin(string userName, string password) {
          // 1. test case
          if(userName = "username" && password == "pwd") return true;
          // 2. your case
          // 连接数据库,验证用户和秘密
          // ....
          return false;
    }
      

  2.   


    在一个页面上存在多个按钮,有的时候希望按回车直接实现点击某按钮的效果,解决方法如下: 
    <script language="javascript"> 
    function document.onkeydown() 

    var e=event.srcElement; 
    if(event.keyCode==13) 

    document.getElementById("需要点击的那个按钮的id").click(); 
    return false; 


    </script> 
    如果页面上有多行文本框,在多行文本框内回车仅仅想实现换行而不是提交表单这么修改 
    if(e!=document.getElementById("多行文本框的id")&&event.keyCode== 13) 
      

  3.   

    在page_load里面添加
    TextBox1.Attributes.Add("onkeydown", "if(event.keyCode==13){document.all.ImageButton1.focus();document.all.ImageButton1.click();}");
      

  4.   

    <form   name=form1   onkeydown="if(event.keyCode=13){document.form1.submit();}">  
      ...  
      </form>
      

  5.   

    onkeydown="javascript:textonkeydown()"if(event.keyCode==13 && mybox!="")   
    {   
       document.getElementById("Button1").click();
    }Button1隐藏