Solved

use Entre button to jump between two textboxes

Posted on 2009-05-13
4
275 Views
Last Modified: 2013-12-17
I have two textboxes. Is it possible to use the entre button to jump between the two.
0
Comment
Question by:Mr_Shaw
  • 2
  • 2
4 Comments
 
LVL 6

Expert Comment

by:ViceroyFizzlebottom
ID: 24377369
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
 

Author Comment

by:Mr_Shaw
ID: 24377436
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
 
LVL 6

Accepted Solution

by:
ViceroyFizzlebottom earned 500 total points
ID: 24377587
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
 

Author Closing Comment

by:Mr_Shaw
ID: 31581077
all working

just needed to know about focus()

thanks
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question