2012-01-30 120 views
0

我有一个asp.net登录控件。它工作正常,但你必须按下实际的按钮登录才能登录。我想这样做,如果用户也按下输入。如何才能做到这一点?asp.net登录控件。当输入被点击时,提交登录

+0

的可能重复http://stackoverflow.com/questions/3237377/allow-enter-key-to-login-in-asp-net或http://计算器.com/questions/201776/submit-login-control-button-when-i-hit-enter – 2012-01-30 02:32:37

回答

0

对此有一些解决方法。看看代码片段。 (无需添加面板控制)

protected void Page_Load(object sender, EventArgs e) 
    { 
    TextBox Password = (TextBox)Login1.FindControl("Password"); 
    Button ButtonLogin = (Button)Login1.FindControl("LoginButton"); 
    Password.Attributes.Add("onKeyPress", "javascript:if (event.keyCode == 13) __doPostBack('" + ButtonLogin.UniqueID + "','')"); 
    }