Solved

use Entre button to jump between two textboxes

Posted on 2009-05-13
4
280 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

729 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