I have a WebDialog which I am using as a confirmation message with ‘Save’ and ‘Don’t Save’ buttons. I would like to handle each case when the end user clicks either button.
When instantiating the WebDialog (in the Pressed event of a button), I run the following:
Session.WarningDialog = New ConfirmationWebDialog("Save changes?", "Do you want to save changes to all input fields?")
AddHandler Session.WarningDialog.DontSaveButton.Pressed, AddressOf ClearAllHandler
AddHandler Session.WarningDialog.SaveButton.Pressed, AddressOf SaveHandler
Session.WarningDialog.Show
Since both Addhandler are created before the end user even clicks an option, where is best to RemoveHandler? Is it best to remove both handlers in each of the methods (ClearAllHandler and SaveHandler).
I am just wondering what is best practice since if I had many more AddHandler, I would need to copy all RemoveHandler commands in every hander functions. This approach seems like it’s prone to forgetting to RemoveHandler causing object leak. Is there a better way to approach this?