问题:.net下的login控件当页面再用了一个按钮控件时,回车键替代不了点击登录按钮,
解决的方法:
在页面的.cs文件中加入代码
protected void Page_Load(object sender, EventArgs e)
{
TextBox password = (TextBox)this.logUser.FindControl("password");
ImageButton LoginImageButton=(ImageButton)this.logUser.FindControl("LoginImageButton");
if (password != null)
{
password.Attributes.Add("回车", "if(event.keyCode==13)document.getElementById('" + LoginImageButton.ClientID + "').focus();");
}
}
其中 password,LoginImageButton控件都是在login控件里面,所以要先找到这两个控件,
注释:password 密码(TextBox) LoginImageButton 登录(ImageButton )