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?
Leave Event Always Triggering Twice
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- gkhairallah
- Posts: 44
- Last visit: Thu Jun 15, 2023 12:55 pm
- Has voted: 2 times
Re: Leave Event Always Triggering Twice
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.
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.
Brittney
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
- gkhairallah
- Posts: 44
- Last visit: Thu Jun 15, 2023 12:55 pm
- Has voted: 2 times
Re: Leave Event Always Triggering Twice
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!
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!