Solved

use Entre button to jump between two textboxes

Posted on 2009-05-13
4
273 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
all working

just needed to know about focus()

thanks
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now