Solved

use Entre button to jump between two textboxes

Posted on 2009-05-13
4
277 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

685 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