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:
- Session (preume I am using the stateserver)
- What happens to all the other users - will they be logged out?
- Application pool recycling due to changes to some compilation??
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" inUserContro
l 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 aboveTextBox's
value from the form, useRequest.Forms["UserControl1_TextBox1"]
. Now what happens when you replace oneUserControl
with another that has the sameClientID
? The second gets the data of the first.Recommendations:
Always assign a unique ID to the
UserControl
in itsID
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 theViewState
to properly distribute its contents without getting aViewState
corrupted error.LoadControl
to get the originalUserControl
. Then before loading the second, set the first's Visible property to false to remove it.