Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Losing focus on postback

Status
Not open for further replies.

Peppi

Programmer
Apr 9, 2001
205
CA
Hi,

I have a postback occuring when the user changes the text in a textbox within a gridview. Once the user tabs off the field the TextChanged event executes as expected. However, when my page is refreshed, I want the focus to be set back to the control that the user had originally tabbed to just before the postback occurred. How can I know which control that was?

Thx.
 
What is the purpose of the TextChanged event? This is generally not a very good event to use for the web and I would recomend you find another way if possible.

If you explain the purpose for the event, then maybe we can help you out.

Senior Software Developer
 
Sure.

I have two textboxes. If the value of either one of them changes, then I need to update the 'Total' column for that row of the grid, which is really just textbox1 * textbox2.

I just discovered another problem doing things this way. If I change one of the values in the textboxes, then click on my Save button to save the changes, only the TextChanged event executes and my save is not performed.

Do you have an alternate suggestion that would eliminate these problems?

Thanks so much.

 
I would lean toward 2 text boxes, an Update Total Button and a Save Button. OR... Possibly 2 Text Boxes and your save button, then find a way to use JavaScript to update the total on a Javascript TextChanged or KeyDown event of some sort.

What you have now would work great for a Console Application, but it just is not going to work in the Web Application world.

Senior Software Developer
 
You could also use jbenson001's info to determine the submitting control and then use JavaScript to place the focus on the next control during the client Side Form Load... but here is the real problem. You are developing on your pc where the postback is so fast that it's almost not noticeable... but when you get it into the real world people will rapidly enter the following key sequence like "123 [TAB] 456" and the postback on the Tab key will erase their entry of 456 because it never got submitted with the page.

Nothing, other than errors, frustrates users more than having to enter things more than once. Know what I mean? ;o)

Senior Software Developer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top