Click here to Skip to main content
15,881,882 members
Articles / Web Development / ASP.NET
Alternative
Tip/Trick

ASP.NET Load WebUserControl Programmatically and Invoke Method using Reflection

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
10 Jan 2011CPOL 5.9K   1  
Why invoke methods on a user web control that is required to be loaded dynamically
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:

  1. 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.
  2. 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.
  3. 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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Rubicon
Netherlands Netherlands
Currently Herre Kuijpers is employed at Rubicon. During his career he developed skills with all kinds of technologies, methodologies and programming languages such as c#, ASP.Net, .Net Core, VC++, Javascript, SQL, Agile, Scrum, DevOps, ALM. Currently he fulfills the role of software architect in various projects.

Herre Kuijpers is a very experienced software architect with deep knowledge of software design and development on the Microsoft .Net platform. He has a broad knowledge of Microsoft products and knows how these, in combination with custom software, can be optimally implemented in the often complex environment of the customer.

Comments and Discussions

 
-- There are no messages in this forum --