3

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:

  1. Session (preume I am using the stateserver)
  2. What happens to all the other users - will they be logged out?
  3. 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.

2
  • I would recommend that you look into the Portal Framework that comes built into ASP.Net. It allows you to create modular web sites, which is kind of similar to what you are attempting to do. It might be worth looking at it to see if it fits your needs, so that you don't have to reinvent the wheel. It also allows for personalization, so that different users can have customized views of the web site. Commented Dec 28, 2010 at 10:21
  • Your feedback is not really addressing the question. I have actually built in jquery what MS does with their portal with full fancy drag and drop with dynamically loading HTML editors. Commented Jan 11, 2011 at 22:11

2 Answers 2

1

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:

  1. Always assign a unique ID to the UserControl in its ID property.

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

  3. So on Post_Back, I recommend calling LoadControl to get the original UserControl. Then before loading the second, set the first's Visible property to false to remove it.
Sign up to request clarification or add additional context in comments.

1 Comment

Do I need to pre-compile my user controls before adding them to a pre-compiled site - the user controls will be outside of the web application directory.
0
  1. No issue on session
  2. No
  3. No

My only suggestion is you read:

http://weblogs.asp.net/infinitiesloop/archive/2006/08/25/TRULY-Understanding-Dynamic-Controls-_2800_Part-1_2900_.aspx

http://weblogs.asp.net/infinitiesloop/archive/2006/08/30/TRULY-Understanding-Dynamic-Controls-_2800_Part-2_2900_.aspx

http://weblogs.asp.net/infinitiesloop/archive/2006/08/30/TRULY-Understanding-Dynamic-Controls-_2800_Part-3_2900_.aspx

http://weblogs.asp.net/infinitiesloop/archive/2006/10/16/TRULY-Understanding-Dynamic-Controls-_2800_Part-4_2900_.aspx

The fact you're currently using a 'Web Site' rather than a web Application doesn't change your ability to add controls dynamically. Tho it would be rather beneficial if MS just removed 'Web Site' altogether since it creates nothing but problems. Thats a different argument for another day tho.

12 Comments

Super articles - but I don't think they address the question of dynamically loading user controls into a pre-compiled web application.
I should have mentioned that I have dynamically loaded user controls in the past ok into a "website" so I am comfortable with how to do it. I'm more concerned with how to do it properly in a specific type of deployment.
They help you understand how the controls are being loaded. If you had a user control, that was like a calculator, and you dynamically loaded it, the events wouldn't just be magically raised on those controls. If you read those articles you will understand why and how, without needing to come back to Stack Overflow for the 30 questions you will need to ask when you run into all the issues of dynamically loading controls.
You can do what you've been doing in the past then, in a Web Application.
I have only been using websites in the past not web applications but now i am switching to web applications and thinking before I jump which is why i am checking the impact of such decisions first.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.