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

J

johngilmer

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.
 
B

Brock Allen

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
modifier.
 
D

David Lloyd

John:

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
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.
 
J

johngilmer

David,
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.
John
 
B

Brock Allen

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top