In this post, I list three things to note about why you would want to invoke methods on a user web control that is required to be loaded dynamically.
Perhaps you should explain a bit regarding the context of this tip.
e.g. Why would you want to invoke methods on a user web control that is required to be loaded dynamically?
There are three things:
- It sounds to me as a code smell: apparently, the control contains logic that is used by other methods outside of the control. Therefore, a better solution would be to encapsulate that logic in a reusable component outside of the
webcontrol
, so the webcontrol
would not need to be loaded dynamically in the first place. - Most of the example code demonstrates the use of reflection, which is not specific to web controls and therefore, kind of miss the point of this tip/trick.
- In my opinion also, the use of reflection is a code smell. Dynamic execution of methods (without compile-time type checking) should be avoided whenever possible as it may introduce runtime errors and reduces maintainability: code becomes less readable and understandable.
History
- 12th March, 2010: Initial version
====================================
just because you can, doesn't mean you should.