Simulate Enter In TextBox

2 posts, 1 answers
  1. July
    July avatar
    205 posts
    Member since:
    Jul 2011

    Posted 09 Dec 2011 Link to this post

    I have a login Page,.
    I need simulate 2 enters.

    The first one : when user press Enter in userName --> set focus in Pass textbox
    When user press in Pass -> simulate Enter (login)

    I try, I it does nto work..


    This is my code

    Aspx

    <%

     

    @ Page Title="" Language="C#" MasterPageFile="~/UI/Home.Master" AutoEventWireup="true"

     

     

     

    CodeBehind="Login.aspx.cs" Inherits="WebSearch.UI.Registration.Login" %>

     

    <

     

     

    asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

     

    </

     

     

    asp:Content>

     

    <

     

     

    asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server

     

     

     

    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">

     

     

     

    <AjaxSettings>

     

     

     

    <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">

     

     

     

    <UpdatedControls>

     

     

     

    <telerik:AjaxUpdatedControl ControlID="loginPanel_DIV" LoadingPanelID="RadAjaxLoadingPanel1"/>

     

     

     

    <telerik:AjaxUpdatedControl ControlID="pnlResetPass_DIV" LoadingPanelID="RadAjaxLoadingPanel" />

     

     

     

    </UpdatedControls>

     

     

     

    </telerik:AjaxSetting>

     

     

     

    <telerik:AjaxSetting AjaxControlID="btnSave">

     

     

     

    <UpdatedControls>

     

     

     

    <telerik:AjaxUpdatedControl ControlID="loginPanel_DIV" LoadingPanelID="RadAjaxLoadingPanel1"/>

     

     

     

     

    </UpdatedControls>

     

     

     

    </telerik:AjaxSetting>

     

     

     

    <telerik:AjaxSetting AjaxControlID="hlForgotPassword">

     

     

     

    <UpdatedControls>

     

     

     

    <telerik:AjaxUpdatedControl ControlID="pnlResetPass_DIV" LoadingPanelID="RadAjaxLoadingPanel1"/>

     

     

     

     

    </UpdatedControls>

     

     

     

    </telerik:AjaxSetting>

     

     

     

    </AjaxSettings>

     

     

     

    </telerik:RadAjaxManager>

     

     

     

    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />

     

     

     

    <div runat="server" ID="loginPanel_DIV">

     

     

     

    <asp:Panel ID="loginPanel" runat="server">

     

     

     

     

    <div class="containerRegistration" runat="server" >

     

     

     

     

    <div class="titleRegistration">

     

     

     

    <div class="lblTitle">

     

     

     

    <asp:Label runat="server" ID="lblTitle" /> <asp:Label ID="lblLogOfftext" runat="server" CssClass="logOff"></asp:Label> </div>

     

     

     

    </div>

     

     

     

    <div class="loginContainer">

     

     

     

    <div class="labelLogin">

     

     

     

    <asp:Label runat="server" ID="lblLoginId" /></div>

     

     

     

    <div class="textBoxLogin">

     

     

     

    <asp:TextBox runat="server" ID="txtloginId" MaxLength="50" Width="200px" />

     

     

     

    <asp:RequiredFieldValidator CssClass="validator" ControlToValidate="txtloginId" runat="server"

     

     

     

    ErrorMessage="*" ValidationGroup="Login"></asp:RequiredFieldValidator>

     

     

     

     

    </div>

     

     

     

    <div class="clear">

     

     

     

    </div>

     

     

     

    <div class="labelLogin">

     

     

     

    <asp:Label runat="server" ID="lblPass" /></div>

     

     

     

    <div class="textBoxLogin">

     

     

     

    <asp:TextBox runat="server" AutoPostBack="true" AutoCompleteType="None" ID="txtPass" MaxLength="50" TextMode="Password" Width="200px" />

     

     

     

    <asp:RequiredFieldValidator CssClass="validator" ControlToValidate="txtPass" runat="server"

     

     

     

    ErrorMessage="*" ValidationGroup="Login"></asp:RequiredFieldValidator>

     

     

     

    <div class="clear">

     

     

     

    </div>

     

     

     

    <asp:CustomValidator ID="cvLoginId" runat="server" Display="Dynamic" ControlToValidate="txtPass"

     

     

     

    CssClass="validator" OnServerValidate="cvLoginId_ServerValidate" ValidationGroup="Login"></asp:CustomValidator></div>

     

     

     

    <div class="remember">

     

     

     

    <asp:CheckBox runat="server" ID="chkRemember"></asp:CheckBox>

     

     

     

     

    &nbsp;&nbsp;&nbsp;&nbsp;

     

     

     

     

    <asp:LinkButton ID="hlForgotPassword" runat="server" OnClick="hlForgotPassword_Click" CausesValidation="true" ValidationGroup="Forgot"></asp:LinkButton>

     

     

     

     

    </div>

     

     

     

    <div class="buttonLogin" style="position: static">

     

     

     

    <telerik:RadButton Width="40px" runat="server" ID="btnLogin" Skin="Vista" OnClick="btnLogin_Click" ValidationGroup="Login">

     

     

     

    </telerik:RadButton>

     

     

     

    <telerik:RadButton runat="server" Width="40px" ID="btnCancel" Skin="Vista">

     

     

     

    </telerik:RadButton>

     

     

     

    </div>

     

     

     

     

    <div style="width: 100%; margin-left: 60%; margin-top:5%;">

     

     

     

    <asp:Label ID="lblValidationText" Style="margin-top: 15px" CssClass="validator" runat="server"

     

     

     

    Font-Italic="true"></asp:Label></div>

     

     

     

    </div>

     

     

     

    </div>

     

     

     

    </asp:Panel>

     

     

     

    </div>

     

     

     

     

    <div id="pnlResetPass_DIV" runat="server">

     

     

     

    <asp:Panel ID="pnlResetPass" runat="server">

     

     

     

    <div class="containerRegistrationReset" runat="server" >

     

     

     

    <div class="titleRegistration">

     

     

     

    <div class="lblTitle">

     

     

     

    <asp:Label runat="server" ID="lblReset" /></div>

     

     

     

    </div>

     

     

     

    <div style="width: 100%; margin-left: 10%">

     

     

     

    <asp:Label ID="lblInformation" Style="margin-top: 15px" CssClass="validator" runat="server" Visible="false"

     

     

     

    Font-Italic="true"></asp:Label></div>

     

     

     

    <div class="loginContainer">

     

     

     

    <div class="labelLogin">

     

     

     

    <asp:Label runat="server" ID="lblUserId" /></div>

     

     

     

    <div class="textBoxLogin">

     

     

     

    <asp:TextBox runat="server" ID="txtUserId" MaxLength="50" Width="200px" />

     

     

     

    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" CssClass="validator" ControlToValidate="txtUserId"

     

     

     

    runat="server" ErrorMessage="*" ></asp:RequiredFieldValidator>

     

     

     

    <br />

     

     

     

    <asp:CustomValidator ID="cvExistLogin" runat="server" CssClass="validator" ControlToValidate="txtUserId"

     

     

     

    OnServerValidate="cvExistLogin_ServerValidate" Display="Dynamic"></asp:CustomValidator>

     

     

     

     

    </div>

     

     

     

    <div class="clear"></div>

     

     

     

    <div class="buttonLogin" style="position: static">

     

     

     

    <telerik:RadButton Width="40px" runat="server" ID="btnReset" Skin="Vista" OnClick="btnReset_Click" >

     

     

     

    </telerik:RadButton>

     

     

     

    <telerik:RadButton runat="server" Width="40px" ID="btnCancelReset" Skin="Vista" OnClick="CancelReset_Click">

     

     

     

    </telerik:RadButton>

     

     

     

    </div>

     

     

     

     

    </div><br />

     

     

     

    <div style="width: 100%; margin-left: 60%">

     

     

     

    <asp:Label ID="lblValidation" Style="margin-top: 15px" CssClass="validator" runat="server"

     

     

     

    Font-Italic="true"></asp:Label></div>

     

     

     

    <br />

     

     

     

     

    </div>

     

     

     

    </asp:Panel>

     

     

     

    </div>

     

     

    </

     

     

    asp:Content>

     



    ASPX.Cs

    using

     

     

    System;

     

    using

     

     

    System.Globalization;

     

    using

     

     

    System.Resources;

     

    using

     

     

    System.Web;

     

    using

     

     

    WebSearch.Components;

     

    using

     

     

    WebSearch.SecurityModel;

     

     

    namespace

     

     

    WebSearch.UI.Registration

     

    {

     

     

    public partial class Login : System.Web.UI.Page

     

    {

    #region

     

     

    Properties&Variables

     

     

     

     

    private string _culture;

     

     

     

    private readonly smOrganization _organization = new smOrganization();

     

     

     

    private ResourceManager _resources;

     

    #endregion

    #region

     

     

    Events

     

     

     

    protected void Page_Load(object sender, EventArgs e)

     

    {

     

     

    if (Page.IsPostBack) return;

     

     

    LoadSettings();

    LoadLogin();

    }

     

     

    protected void Page_Init(object sender, EventArgs e)

     

    {

    GetInfo();

    }

     

     

    protected void btnReset_Click (object sender, EventArgs e)

     

    {

     

     

    if (!Page.IsValid) return;

     

    _organization.User = _organization.GetUser(_organization.GetUser(txtUserId.Text));

    _organization.SendPasswordChangeEmail();

    lblInformation.Visible =

     

    true;

     

    }

     

     

    protected void btnLogin_Click(object sender, EventArgs e)

     

    {

    LoginUser();

    }

     

     

    protected void cvLoginId_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)

     

    {

    _organization.User =

     

    new smUser {Loginid = txtloginId.Text, Password = Encript.EncryptText(txtPass.Text)};

     

     

     

     

    if (_organization.ExistLogin(txtloginId.Text, 0) == false || _organization.LoginUser() == false)

     

    {

    args.IsValid =

     

    false;

     

    }

     

     

    else

     

    {

    args.IsValid =

     

    true;

     

     

     

    App.SetCurrentUserId(_organization.GetUser(txtloginId.Text));

     

    }

     

    }

     

     

     

    protected void CancelReset_Click(object sender, EventArgs e)

     

    {

    cvExistLogin.Enabled =

     

    false;

     

    loginPanel.Visible =

     

    true;

     

    pnlResetPass.Visible =

     

    false;

     

    Response.Redirect(

     

    "~/UI/Registration/Login.aspx");

     

    }

     

     

    protected void cvExistLogin_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)

     

    {

    args.IsValid = _organization.ExistLogin(txtUserId.Text, 0);

    }

     

     

    protected void hlForgotPassword_Click(object sender, EventArgs e)

     

    {

    cvExistLogin.Enabled =

     

    true;

     

    loginPanel.Visible =

     

    false;

     

    pnlResetPass.Visible =

     

    true;

     

    LoadSettingForgot();

    }

     

     

    protected void txtPass_OnTextChanged(object sender, EventArgs e)

     

    {

    LoginUser();

    }

    #endregion

     

    #region

     

     

    Method

     

     

     

    private void LoginUser()

     

    {

    Page.Validate(

     

    "Login");

     

     

     

    if (!ValidateFailedUser(txtloginId.Text))

     

    {

    lblLogOfftext.Text = _resources.GetString(

     

    "errorUser" , new CultureInfo(_culture));

     

    RadAjaxManager1.Alert(_resources.GetString(

     

    "errorUser" , new CultureInfo(_culture)));

     

     

     

    return;

     

    }

     

     

     

    if (!Page.IsValid) return;

     

     

     

     

    if (chkRemember.Checked)

     

    {

     

     

    HttpCookie authUser = Request.Cookies.Get("authUser");

     

     

     

    if (authUser== null)

     

    {

    authUser =

     

    new HttpCookie("authUser");

     

    Response.Cookies[

     

    "authUser"].Expires = DateTime.Now.AddDays(App.GetExpireDays());

     

    authUser.Values.Add(

     

    "authUserName", txtloginId.Text);

     

    Response.Cookies.Add(authUser);

    }

    }

     

     

    else

     

    {

     

     

    HttpCookie authUser = new HttpCookie("authUser") {Expires = DateTime.Now.AddDays(-1d)};

     

    Response.Cookies.Add(authUser);

    }

     

     

    App.GetControls();

     

     

     

    App.GetPersistenceTable();

     

    Response.Redirect(

     

    "~/UI/DocumentsList.aspx");

     

    }

     

     

     

    private bool ValidateFailedUser(string loginId)

     

    {

     

     

    return _organization.ValidateFailedUser(loginId);

     

    }

     

     

     

    private void LoadSettingForgot()

     

    {

    lblReset.Text = _resources.GetString(lblReset.ID,

     

    new CultureInfo(_culture));

     

    lblUserId.Text = _resources.GetString(lblLoginId.ID,

     

    new CultureInfo(_culture));

     

     

    }

     

     

    private void LoadLogin()

     

    {

     

     

    HttpCookie authUser = Request.Cookies.Get("authUser");

     

     

     

    if (authUser != null)

     

    {

    txtloginId.Text = authUser.Values[

     

    "authUserName"];

     

    }

    }

     

     

    private void LoadSettings()

     

    {

    lblTitle.Text = _resources.GetString(lblTitle.ID,

     

    new CultureInfo(_culture));

     

    lblLoginId.Text = _resources.GetString(lblLoginId.ID,

     

    new CultureInfo(_culture));

     

    lblPass.Text = _resources.GetString(lblPass.ID,

     

    new CultureInfo(_culture));

     

    btnLogin.Text = _resources.GetString(btnLogin.ID,

     

    new CultureInfo(_culture));

     

    btnCancel.Text = _resources.GetString(btnCancel.ID,

     

    new CultureInfo(_culture));

     

    chkRemember.Text = _resources.GetString(chkRemember.ID,

     

    new CultureInfo(_culture));

     

    cvLoginId.ErrorMessage = _resources.GetString(cvLoginId.ID,

     

    new CultureInfo(_culture));

     

    hlForgotPassword.Text = _resources.GetString(hlForgotPassword.ID,

     

    new CultureInfo(_culture));

     

    lblInformation.Text = _resources.GetString(lblInformation.ID,

     

    new CultureInfo(_culture));

     

    lblValidationText.Text = _resources.GetString(lblValidationText.ID,

     

    new CultureInfo(_culture));

     

    lblValidation.Text = _resources.GetString(lblValidationText.ID,

     

    new CultureInfo(_culture));

     

    cvExistLogin.ErrorMessage = _resources.GetString(cvExistLogin.ID,

     

    new CultureInfo(_culture));

     

    btnReset.Text = _resources.GetString(btnReset.ID,

     

    new CultureInfo(_culture));

     

    btnCancelReset.Text = _resources.GetString(btnCancelReset.ID,

     

    new CultureInfo(_culture));

     

    cvExistLogin.Enabled =

     

    false;

     

    pnlResetPass.Visible =

     

    false;

     

     

     

    if ( (Request.Cookies["authUser"] != null)) chkRemember.Checked = true;

     

     

     

    if (Request.QueryString["L"] == "Off")

     

    {

    lblLogOfftext.Text = _resources.GetString(lblLogOfftext.ID,

     

    new CultureInfo(_culture));

     

    }

     

     

    }

     

     

    private void GetInfo()

     

    {

    _culture =

     

    App.CurrentCulture();

     

    _resources =

     

    App.GetRegistrationResources("Login");

     

    }

     

    #endregion

     

    }

    }





  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 11 Dec 2011 Link to this post

    Hello,

    Try the following javascript in first TextBox and attach same in second TextBox.

    JS:
    <script type="text/javascript">
     function OnKeyPress(sender, args)
      {
          if (args.get_keyCode() == 13)
           {
             var radtxt1 = $find("<%=RadTextBox2.ClientID%>");
             radtxt1.focus();
           }
      }
    </script>

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top