cancel
Showing results for 
Search instead for 
Did you mean: 

Event firing twice for button click

Former Member
0 Kudos

I have an add-on that puts a new button on the Item Master form. Clicking that item brings up a new data entry form. Everything works well except that it appears the click event is firing twice. I have this code to capture the click for the custom button:

If pVal.Before_Action = False And pVal.ItemUID = "btnMxSet" Then

..load my new form

End If

The problem is that the form tries to load twice because the event is fired twice. I added an SBO message box before loading the form and it only fires off once. I suppose I can check to see if the form is loaded, but I want to see why the event fires twice.

Any ideas? If not, what's the best way to check to see if a given form is loaded?

The people on this forum are very helpful!

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

rasmuswulff_jensen
Active Contributor
0 Kudos

You should also add a pVal.EventType == BoEventTypes.et_ITEM_PRESSED...

Complete code:


public static bool isButtonClick(string UID) {
   return (!pVal.BeforeAction && pVal.ItemUID==UID && pVal.EventType == BoEventTypes.et_ITEM_PRESSED);
}

Former Member
0 Kudos

Thanks Rasmus, that seemed to have solved the problem.

I'm guessing one of the two events that fired was not an ITEM_CLICKED event but the button was still marked as the current item.

rasmuswulff_jensen
Active Contributor
0 Kudos

Yes... Item_Click is fired beforee item_pressed

.... But remember, you should almost all the time use item_pressed and not item_click... You can try to see the difference if you set the event to item_click, left click button but not release the button and move the mouse away from the button.... them try moving the mouse over the button again...

In all my addons I don't think i've used item_click yet

Former Member
0 Kudos

Hi Curtis,

Another reason for your code executing twice is because it will be executed when BeforeAction is true and when BeforeAction is false. You should check this in your code as well.

if pVal.BeforeAction = True then
...
else
...
end if

Hope it helps,

Adele

Answers (0)