vb.net - Asp.net control with custom event -


i have control has custom event.

currently define other event

public event contentchanged eventhandler 

but today found article had totally different way of handling it

shared readonly contentchangedkey new object()  public custom event contentchanged eventhandler     addhandler(value eventhandler)         me.events.addhandler(contentchangedkey, value)     end addhandler     removehandler(value eventhandler)         me.events.removehandler(contentchangedkey, value)     end removehandler     raiseevent(sender object, e eventargs)         dim contentchangeddelegate eventhandler = _             me.events(contentchangedkey)         contentchangeddelegate(sender, e)     end raiseevent  end event 

the second way seems overly complicated first example doesn't??

it has overcomplication :)

in other words can add in there other kind of processing needs done when envent happens or bound to. since controlling actions taken when event handler added, removed or raised, can custom things.

for example had control had 5 buttons. 1 of buttons usless unless event x being handled.

with custom event handler this:

public custom event contentchanged eventhandler     addhandler(value eventhandler)         me.events.addhandler(contentchangedkey, value)         me.specialbutton.visible = true     end addhandler     removehandler(value eventhandler)         me.events.removehandler(contentchangedkey, value)         me.specialbutton.visible = false      end removehandler     raiseevent(sender object, e eventargs)         dim contentchangeddelegate eventhandler = _             me.events(contentchangedkey)         contentchangeddelegate(sender, e)     end raiseevent  end event 

if did not have custom event handler difficult kind of logic. comes down granularity; how control need?

of course need sure when addhandler or removehandler being triggered expect use in there real. this overly simplified example


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -