I am trying to create my own website management framework similar to DNN/SiteFinity (only a mucho cut down version).
One of the big (but common) features is to be able to dynamically add user controls to provide additional functionality.
I would prefer to use a pre-compiled .NET "Web Application" over a dynamically compiled "Website".
What are the implications of using LoadControl method to dynamically add a user control for a pre-compiled web applications with specific regard to:
I am not sure I have ever dynamically added a user control to a pre-compiled web applications as I have mainly been using "Websites" so I am making a large presumption that it will work because if the website is pre-compiled, does this mean the dynamically added user control will be dynamically compiled as required even though the site is pre-compiled?
EDIT
I also forgot to mention that the user controls will be outside of the application directory and so won't be published during web deploy - they will be uploaded via another website.
Thanks! Dan.
You can dynamically add user control with in your precompiled website.
I give a description about user control life cycle:
Every control on the page has a unique ID called the ClientID. (That's an actual property on each control.) A user control is a "naming container". That means each control it contains also contains the ID of the User control. For example, "TextBox1" in UserControl with the ID "UserControl1" will have the clientID:
UserControl1_TextBox1.
Post back retrieves the values from each field by the ClientID. For example, to get the above TextBox's value from the form, use Request.Forms["UserControl1_TextBox1"].
Now what happens when you replace one UserControl with another that has the same ClientID? The second gets the data of the first.
Recommendations:
Always assign a unique ID to the UserControl in its ID property.
You should always recreate the controls of the page you sent to the
browser on postback before rearranging them. That allows the
original controls to load their data and run their event handlers.
It also allows the ViewState to properly distribute its contents
without getting a ViewState corrupted error.
LoadControl to get the original
UserControl. Then before loading the second, set the first's Visible
property to false to remove it.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With