Link to home
Start Free TrialLog in
Avatar of Mr_Shaw
Mr_Shaw

asked on

use Entre button to jump between two textboxes

I have two textboxes. Is it possible to use the entre button to jump between the two.
Avatar of ViceroyFizzlebottom
ViceroyFizzlebottom
Flag of United States of America image

You should be able to create an event handler method on the button's OnClick event. Inside that method, I believe you could use the "__LASTFOCUS" property to determine which textbox had focus when the button was pressed, and subsequently set the focus to the other text box.
protected void OnClick_EventHandler(object sender, EventArgs e)
{
    string ctrlName = page.Request.Params.Get("__LASTFOCUS");
    Control ctl = Page.FindControl(ctrlName);
 
    if(ctl.GetType() == typeof(TextBox))
    {
        // Here you could make sure the TextBox control
        // is in fact one of the two you wanted, then
        // set the other textbox's focus property
        OtherTextBox.Focus();
    }
}

Open in new window

Avatar of Mr_Shaw
Mr_Shaw

ASKER

Since the enter button will be pressed when the user is in the textbox, should the code not be on the textbox textchanged event.
ASKER CERTIFIED SOLUTION
Avatar of ViceroyFizzlebottom
ViceroyFizzlebottom
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mr_Shaw

ASKER

all working

just needed to know about focus()

thanks