Hooking into a getter or setter of .Net class

J

Josh Valino

Hi,

Is there anyway that I can hook into a getter and setter of a property for a
..Net control across my application? Specifically, what I'd like to do is
execute some code whenever a System.Web.UI.WebControls.TextBox.Text property
is set'd or get'd. I'm aware there are things I can do such as wrap this
control, but for political reasons, I need to try to come up with a solution
that will involve changing or adding as little code as possible.

I am using .Net 3.5, so if there was this kind of functionality added that
would allow this, as it's similar to extension methods, I'd be able to use
that.

Thanks
 
M

Marc Gravell

You need to use notification events really; you can't (without some
*major* hacking, i.e. pretending to be a debugger) just link into
arbitraty code. Fortunately, there is a TextChanged event you can
subscribe to.

If you want to apply this to all controls, you'd probably have to
override one of the init methods in ASP.NET to search (recursively)
for TextBox controls and subscribe to the event. I can't tell you
which init method to override as I'm not an ASP.NET expert, but try an
ASP.NET forum?

Marc
 
B

Ben Voigt [C++ MVP]

Marc said:
You need to use notification events really; you can't (without some
*major* hacking, i.e. pretending to be a debugger) just link into
arbitraty code. Fortunately, there is a TextChanged event you can
subscribe to.

Or use an aspect-oriented programming (AOP) weaving tool, which will
automatically modify the IL after compilation.
 

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

Top