CTextBox.NextFocusOnEnter: Point to the next control to focus on Enter key.

This commit is contained in:
2015-09-27 19:39:14 +02:00
parent a7c8a698f2
commit 4762207e2d
4 changed files with 23 additions and 17 deletions

View File

@@ -17,6 +17,8 @@ namespace VAR.Focus.Web.Controls
private bool _markedInvalid = false; private bool _markedInvalid = false;
private Control _nextFocusOnEnter = null;
#endregion #endregion
#region Properties #region Properties
@@ -45,6 +47,12 @@ namespace VAR.Focus.Web.Controls
set { _markedInvalid = value; } set { _markedInvalid = value; }
} }
public Control NextFocusOnEnter
{
get { return _nextFocusOnEnter; }
set { _nextFocusOnEnter = value; }
}
#endregion #endregion
#region Control life cycle #region Control life cycle
@@ -72,6 +80,14 @@ namespace VAR.Focus.Web.Controls
Attributes.Add("placeholder", _placeHolder); Attributes.Add("placeholder", _placeHolder);
} }
if (_nextFocusOnEnter!=null)
{
this.Attributes.Add("onkeydown", String.Format(
"if(event.keyCode==13){{document.getElementById('{0}').focus(); return false;}}",
_nextFocusOnEnter.ClientID));
}
// FIX: The framework deletes textbox values on password mode // FIX: The framework deletes textbox values on password mode
if (TextMode == TextBoxMode.Password) if (TextMode == TextBoxMode.Password)
{ {

View File

@@ -28,7 +28,6 @@ namespace VAR.Focus.Web.Pages
void FrmBoard_Init(object sender, EventArgs e) void FrmBoard_Init(object sender, EventArgs e)
{ {
string strIDBoard = GetRequestParm(Context, "idBoard"); string strIDBoard = GetRequestParm(Context, "idBoard");
if (String.IsNullOrEmpty(strIDBoard) == false) if (String.IsNullOrEmpty(strIDBoard) == false)
{ {

View File

@@ -57,9 +57,11 @@ namespace VAR.Focus.Web.Pages
Controls.Add(lblTitle); Controls.Add(lblTitle);
Controls.Add(FormUtils.CreateField("Name/Mail", _txtNameEmail)); Controls.Add(FormUtils.CreateField("Name/Mail", _txtNameEmail));
_txtNameEmail.NextFocusOnEnter = _txtPassword;
_txtNameEmail.PlaceHolder = "Name/Mail"; _txtNameEmail.PlaceHolder = "Name/Mail";
Controls.Add(FormUtils.CreateField("Password", _txtPassword)); Controls.Add(FormUtils.CreateField("Password", _txtPassword));
_txtPassword.NextFocusOnEnter = _btnLogin;
_txtPassword.PlaceHolder = "Password"; _txtPassword.PlaceHolder = "Password";
Controls.Add(FormUtils.CreateField(String.Empty, _btnLogin)); Controls.Add(FormUtils.CreateField(String.Empty, _btnLogin));
@@ -67,11 +69,6 @@ namespace VAR.Focus.Web.Pages
_btnLogin.Click += btnLogin_Click; _btnLogin.Click += btnLogin_Click;
Controls.Add(FormUtils.CreateField(String.Empty, new HyperLink { Text = "Register user", NavigateUrl = "FrmRegister" })); Controls.Add(FormUtils.CreateField(String.Empty, new HyperLink { Text = "Register user", NavigateUrl = "FrmRegister" }));
_txtNameEmail.Attributes.Add("onkeydown", String.Format(
"if(event.keyCode==13){{document.getElementById('{0}').focus(); return false;}}", _txtPassword.ClientID));
_txtPassword.Attributes.Add("onkeydown", String.Format(
"if(event.keyCode==13){{document.getElementById('{0}').focus(); return false;}}", _btnLogin.ClientID));
} }
#endregion #endregion

View File

@@ -81,15 +81,19 @@ namespace VAR.Focus.Web.Pages
Controls.Add(_pnlRegister); Controls.Add(_pnlRegister);
_pnlRegister.Controls.Add(FormUtils.CreateField("Name", _txtName)); _pnlRegister.Controls.Add(FormUtils.CreateField("Name", _txtName));
_txtName.NextFocusOnEnter = _txtEmail;
_txtName.PlaceHolder = "Name"; _txtName.PlaceHolder = "Name";
_pnlRegister.Controls.Add(FormUtils.CreateField("Email", _txtEmail)); _pnlRegister.Controls.Add(FormUtils.CreateField("Email", _txtEmail));
_txtEmail.NextFocusOnEnter = _txtPassword1;
_txtEmail.PlaceHolder = "Email"; _txtEmail.PlaceHolder = "Email";
_pnlRegister.Controls.Add(FormUtils.CreateField("Password", _txtPassword1)); _pnlRegister.Controls.Add(FormUtils.CreateField("Password", _txtPassword1));
_txtPassword1.NextFocusOnEnter = _txtPassword2;
_txtPassword1.PlaceHolder = "Password"; _txtPassword1.PlaceHolder = "Password";
_pnlRegister.Controls.Add(FormUtils.CreateField(String.Empty, _txtPassword2)); _pnlRegister.Controls.Add(FormUtils.CreateField(String.Empty, _txtPassword2));
_txtPassword2.NextFocusOnEnter = _btnRegister;
_txtPassword2.PlaceHolder = "Password"; _txtPassword2.PlaceHolder = "Password";
_btnRegister.Text = "Register"; _btnRegister.Text = "Register";
@@ -102,17 +106,7 @@ namespace VAR.Focus.Web.Pages
pnlButtons.Controls.Add(_btnRegister); pnlButtons.Controls.Add(_btnRegister);
pnlButtons.Controls.Add(_btnExit); pnlButtons.Controls.Add(_btnExit);
_pnlRegister.Controls.Add(FormUtils.CreateField(String.Empty, pnlButtons)); _pnlRegister.Controls.Add(FormUtils.CreateField(String.Empty, pnlButtons));
_txtName.Attributes.Add("onkeydown", String.Format(
"if(event.keyCode==13){{document.getElementById('{0}').focus(); return false;}}", _txtEmail.ClientID));
_txtEmail.Attributes.Add("onkeydown", String.Format(
"if(event.keyCode==13){{document.getElementById('{0}').focus(); return false;}}", _txtPassword1.ClientID));
_txtPassword1.Attributes.Add("onkeydown", String.Format(
"if(event.keyCode==13){{document.getElementById('{0}').focus(); return false;}}", _txtPassword2.ClientID));
_txtPassword2.Attributes.Add("onkeydown", String.Format(
"if(event.keyCode==13){{document.getElementById('{0}').focus(); return false;}}", _btnRegister.ClientID));
Controls.Add(_pnlSuccess); Controls.Add(_pnlSuccess);
_pnlSuccess.Visible = false; _pnlSuccess.Visible = false;