Solved

use Entre button to jump between two textboxes

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 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