By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,694 Members | 1,313 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,694 IT Pros & Developers. It's quick & easy.

UserControl - Leave Event not being raised when press [ENTER] key

P: n/a
I have a usercontrol with code in the "leave" event which updates the final
data back into a database.

This works fine except if I have a default "accept" button on a form and
invoke it by pressing the ENTER key on the keyboard. In this case, it would
appear that whilst the code on the button is executing and therefore
presumably the button actually has focus, the leave event in the user
control is not fired.

Should I be interfacing with another event on the usercontrol instead of the
"leave" event.. or is there some other way round the problem?

Thanks in advance
Simon
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
I'm considering using the LostFocus event. instead of leave.. It looks like
they both get fired? Though it would appear that possibly the Leave event
doesn't get fired in the scenario I describe whereas the LostFocus even
does??? (I've not tested this yet but I'm presuming that it should).

So, to guarantee that my data gets updated, where should I put my updating
code? LostFocus? Leave? or perhaps should I use Validated or Validating???
Do I need to do the update in multiple events (with the pain of running the
update code twice???)

Hope somebody can ease my confusion!!

Regards
Simon

"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I have a usercontrol with code in the "leave" event which updates the
final data back into a database.

This works fine except if I have a default "accept" button on a form and
invoke it by pressing the ENTER key on the keyboard. In this case, it
would appear that whilst the code on the button is executing and therefore
presumably the button actually has focus, the leave event in the user
control is not fired.

Should I be interfacing with another event on the usercontrol instead of
the "leave" event.. or is there some other way round the problem?

Thanks in advance
Simon

Nov 21 '05 #2

P: n/a
I little investigation suggests that if I exit the usercontrol by pressing
ENTER to invoke the default Accept button on the form, that neither the
lostfocus or leave events are raised but the validated event is.

Am I therefore safe to put my update code in the validated event? Is this
guaranteed to be fired once and only once every time that my usercontrol is
exited, either by tabbing away, pressing enter or clicking elsewhere on the
form???

Thanks in advance
Simon
"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:ON**************@TK2MSFTNGP10.phx.gbl...
I'm considering using the LostFocus event. instead of leave.. It looks
like they both get fired? Though it would appear that possibly the Leave
event doesn't get fired in the scenario I describe whereas the LostFocus
even does??? (I've not tested this yet but I'm presuming that it should).

So, to guarantee that my data gets updated, where should I put my updating
code? LostFocus? Leave? or perhaps should I use Validated or
Validating??? Do I need to do the update in multiple events (with the pain
of running the update code twice???)

Hope somebody can ease my confusion!!

Regards
Simon

"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I have a usercontrol with code in the "leave" event which updates the
final data back into a database.

This works fine except if I have a default "accept" button on a form and
invoke it by pressing the ENTER key on the keyboard. In this case, it
would appear that whilst the code on the button is executing and
therefore presumably the button actually has focus, the leave event in
the user control is not fired.

Should I be interfacing with another event on the usercontrol instead of
the "leave" event.. or is there some other way round the problem?

Thanks in advance
Simon


Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.