AddHandler / Remove Handler?

Discussion in 'ASP .Net Web Controls' started by Tim, Apr 15, 2005.

  1. Tim

    Tim Guest

    If you instantiate a web control programmatically in Form_Load and then add
    a click event handler to it using AddHandler MyControl.Click AddressOf
    MyEventHandler, is it necessary to call RemoveHandler MyControl.Click
    AddressOf MyEventHandler in the Page_Unload event? Does not removing
    handlers have any side effects?
    Thanks
    Tim
    Tim, Apr 15, 2005
    #1
    1. Advertising

  2. Tim

    Brock Allen Guest

    In ASP.NET, no, it's not necessary. You typically only do this if your ccode
    that was receiving the event is still running and you no longer want to receive
    the event. Since ASP.NET creates a page for every request, the page and all
    the child contorls are thrown away so no need to stop receiving the event
    as the source of the event is gone itself, so to speak.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > If you instantiate a web control programmatically in Form_Load and
    > then add
    > a click event handler to it using AddHandler MyControl.Click AddressOf
    > MyEventHandler, is it necessary to call RemoveHandler MyControl.Click
    > AddressOf MyEventHandler in the Page_Unload event? Does not removing
    > handlers have any side effects?
    > Thanks
    > Tim
    Brock Allen, Apr 15, 2005
    #2
    1. Advertising

  3. No, that's not necessary in ASP.NET, and it has no real effect.

    --
    I hope this helps,
    Steve C. Orr, MCSD, MVP
    http://SteveOrr.net


    "Tim" <> wrote in message
    news:...
    > If you instantiate a web control programmatically in Form_Load and then
    > add
    > a click event handler to it using AddHandler MyControl.Click AddressOf
    > MyEventHandler, is it necessary to call RemoveHandler MyControl.Click
    > AddressOf MyEventHandler in the Page_Unload event? Does not removing
    > handlers have any side effects?
    > Thanks
    > Tim
    >
    >
    Steve C. Orr [MVP, MCSD], Apr 15, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeffrey A. Voigt

    Help w/AddHandler (Not Firing Off)

    Jeffrey A. Voigt, Aug 10, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    618
    Natty Gur
    Aug 11, 2003
  2. Natty Gur

    Re: Help w/AddHandler (Not Firing Off)

    Natty Gur, Aug 11, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    420
    Jeff Voigt
    Aug 11, 2003
  3. shruds
    Replies:
    1
    Views:
    749
    John C. Bollinger
    Jan 27, 2006
  4. Replies:
    1
    Views:
    682
    Damien
    Feb 22, 2007
  5. Replies:
    0
    Views:
    340
Loading...

Share This Page