views:

56

answers:

3

When the user leaves a textbox control I want to trim any spaces and immediately update the display with the tidied string.

Should this be done in the Leave, Validating or Validated event?

Thanks

Clarence

A: 

onBlur = when the user leaves.

But the user could also submit the form without leaving the tb, e.g., by hitting the enter key. So you may also want to listen for that.

steamer25
This is tagged as windows forms
hypoxide
A: 

The Leave event would be best suited, as it occurs when the focus has left the textbox.

hypoxide
+1  A: 

I would use leave if you simply want to trim the string. Validating is useful if you want to cancel the leave (from tab, enter click etc) and keep the textbox selected.

Tim