I have a quick question I am working on an automation script and have run into an issue. I have created a dialog button and I am trying to run a method when the butto is pressed. so far I have this:
public event EventHandler<EventArgs> Pressed;
public void Button_Pressed(object sender, EventArgs e)
AddPort(sender, e, protocol.Protocol);
I have tried both of these but the method does not trigger when button is pressed
dialog.Button.Pressed += new EventHandler<EventArgs>(Button_Pressed);
dialog.Button.Pressed += (sender,e) => Pressed(sender,e);
I have a drop down list and everything works for the OnChange event but for the button I can't get it to work.
Thank you so much in advance.
Hi Thomas and Floris,
The example that you shared was pretty much what I had, thanks to your questions and help I have been able to finaly solve it.
the issue was after running the dialog again after making a few changes to the original dialog and running the second altered dialog it does not have the event registered so what I did was add the event again before the second controller.Run(dialog).
Thank you for the help
Together with Thomas, I made an IAS that handles a button press that we tested our local DMA. Maybe this can serve as an example?
From the code you posted, it looks like you're registering the event outside of your Dialog class, which we also did in our example. Is it possible that you are adding the event after calling controller.Run(dialog)?
Also note that the ExitSuccess is throwing a ScriptAbortException, which should be caught in the Run function, or it will be rethrown as a fail.
The Engine.Log statement will be logged in SLAutomation.txt .
I assume the button is a property of your dialog class.
Check that the button property does not get overwritten after subscribing to the Pressed event.
In case you are running a very old version of the toolkit, make sure the WantsOnChange property of the button is set to True.
This is not needed on recent versions, and you might not be able to access the property, ignore this if that is the case.
The 2 examples you gave to subscribe seem to be valid.
But I would write it like this:
dialog.Button.Pressed += Button_Pressed;
If nothing worked, would it be possible to share more of the code in the dialog class?