AddHandler does not recognise control event as member

When instantiating a WebDialog, I store it in a property of the Session (The property is defined as type MyDialog) E.g.

Session.Dialog = New MyDialog

I want to handle the dismissed event of Session.Dialog, and so I tried the following straight after instantiating the WebDialog above:

AddHandler Session.Dialog.Dismissed AddressOf Self.MyMethod

However I get an error stating that it does not recognise ‘Dismissed’ as a member of Session.MyDialog. Where am I going wrong?

Think there should be a comma (,) after .Dismissed.


Oh of course. Thanks.

Although I am now getting another error:
Type mismatch error. Expected delegate Delegate(MyDialog.MyDialog), but got delegate Delegate( )

I actually pass parameters to a constructor method of the WebDialog when instantiating it. Has the error got something to do with this? So my code is now as follows:

Session.Dialog = New MyDialog(param1, param2, param3)
AddHandler Session.Dialog.Dismissed, AddressOf Self.MyMethod

No. MyMethod has to be declared with a MyDialog parameter

mdlg as MyDialog

When the event handler is entered, it thus has available (in that parameter) the instance of MyDialog where the event happened.

The params in the New are what you use in your Constructor.

(Pretty sure all the above is correct. I usually get it confused at least once when defining events.)

Thanks a lot! That fixed it.
After following your advice and declaring a MyDialog paramater in the MyMethod signature, I initially tried passing the WebDialog as a parameter after AddressOf as it felt like the intuitive thing to so i.e.

AddHandler Session.Dialog.Dismissed, AddressOf Self.MyMethod(Session.Dialog)

But in this case, this caused an error. I just learnt that Session.Dialog is automatically passed to MyMethod and cannot be explicitly passed in.

What you learned is that AddHandler takes a pointer to the method as it’s second parameter, that’s what the whole AddressOf thing is about.

BTW - make sure you also call RemoveHandler when you’re done with it. Otherwise, you’ll leak dialog objects.