Page 1 of 1

Leave Event Always Triggering Twice

Posted: Fri May 07, 2021 12:23 pm
by gkhairallah
Product, version and build:2021 5.8.188
Operating system: Windows 10
PowerShell version(s): 5.1

Hi, I've been observing an odd behavior, and can't find the cause of it.
I have a "Leave" event on a Textbox that triggers a function. For some reason, the whole event is always triggering twice.

I thought that I had inadvertently associated the same Leave event name with 2 textboxes, but that wasn't the case. To be 100% sure of that, I tried renaming the leave even name to something unique and associated it only with the intended textbox, and the event still triggered twice.

I have tried closing and reopening PowerShell studio just in case, but that didn't resolve it.

Below is a link to a quick video of the issue occurring
https://www.screencast.com/t/MNYGfNby
Thoughts?

Re: Leave Event Always Triggering Twice

Posted: Fri May 07, 2021 1:19 pm
by brittneyr
Does this also happen after running your script outside of PowerShell Studio or when running in console (Ctrl + F8)?

I was not able to reproduce this behavior and without seeing the rest of you code, I can only make suggestions. Though I cannot see if this is the case, its generally a good rule to not use the Focus() method in an event handler that's called because of a focusing event, like Leave. From the video, it looks like you are using the leave event to validate the information entered, I recommend looking into use the Validating event instead.

Re: Leave Event Always Triggering Twice

Posted: Fri May 07, 2021 3:00 pm
by gkhairallah
Thanks for the guidance Brittney!
It appears that the culprit was the: $textbox_password.focus() which was inside the handler, and it was re-triggering the "Leave" event, as the password field has to switch from $textbox_password.Enabled = $false to $textbox_password.Enabled = $true.

I followed your advice by moving that whole process into a validation event, and that worked like a charm! :)

Thanks again!