• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 292
  • Last Modified:

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.
0
Mr_Shaw
Asked:
Mr_Shaw
  • 2
  • 2
1 Solution
 
ViceroyFizzlebottomCommented:
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

0
 
Mr_ShawAuthor Commented:
Since the enter button will be pressed when the user is in the textbox, should the code not be on the textbox textchanged event.
0
 
ViceroyFizzlebottomCommented:
Yes, valid point. I guess an even simpler option would be to simply check which text box has data in it inside the event handler and set the other control's focus.

So

if(!String.Empy(TextBoxOne.Text))
{
    TextBoxTwo.Focus();
}
else
    TextBoxOne.Focus();

Would something like that achieve your goal?
0
 
Mr_ShawAuthor Commented:
all working

just needed to know about focus()

thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now