How can I read the events handlers of a UI object?

Discussion in 'ASP .Net' started by johngilmer, May 5, 2005.

  1. johngilmer

    johngilmer Guest

    I posted this question a couple days ago on , but didn't get any
    answers, so I will try here.

    My issue: there is a link button with an event handler for a Click
    event. I want to create another link button that will act exactly like
    the first. So I want to set its Click event handler to be the same as
    the first one. But I can't figure out how I can see what the first
    one's event handler is.
    thanks in advance.
    johngilmer, May 5, 2005
    1. Advertisements

  2. johngilmer

    Brock Allen Guest

    Oh, you want to interogate a control to get everyone who's registered for
    an event on said control? You can't, as the delegate is private inside of
    the control. If it were public then it'd not be a problem. So you can either
    derive your own that makes it public or use reflection to bypass the access
    Brock Allen, May 5, 2005
    1. Advertisements

  3. johngilmer

    David Lloyd Guest


    If you are using Visual Studio, select the link button and view the
    properties window. Then select the button at the top of this window that
    looks like a lightning bolt. That will show you the events for the link
    button and what event handler is set for the Click event.

    A second method is to examine the InitializeComponent method of the code
    behind page. This will show code for adding the events for a particular
    control on the page.

    For example:

    this.LinkButton1.Click += new System.EventHandler(this.Page_Load);

    David Lloyd

    This response is supplied "as is" without any representations or warranties.
    David Lloyd, May 5, 2005
  4. johngilmer

    johngilmer Guest

    Thanks for the reply. What I want is not to see the handlers at design
    time, but to detect it at runtime. So I want to query the object while
    the application is running to ask it what its event handlers are. But
    it seems from the other response I got from
    Brock Allen that it might not be possible because it's private.
    johngilmer, May 12, 2005
  5. johngilmer

    Brock Allen Guest

    I didn't say you couldn't do it (I don't think I said that). You'd need to
    use reflection to do this.
    Brock Allen, May 12, 2005
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.