views:

27

answers:

1

Hi all,

I want to able to create reusable user controls within my web app and i'm wondering on how to go about doing so.

  1. Should a user controls properties be visible to a form that's using it?
  2. What's the best way to go about loading the controls on the user control from the form thats using it? Should there be a public method within the control that allows you to load it from an external form or should the user control be loaded in the page load event
  3. Is it okay to nest user controls within user controls?

etc...

Thanks for any advice

+1  A: 

1) You only need to make properties visible if any page needs to read or modify information on your control. I personally like to keep my user controls as self contained as possible, and keep this to a minimum.

2) I would just rely on the built in page life cycle to render your control, but it is important to note when each of your control's events fire in relation to your pages. You may find that there are times that you need something on your control to render before something on your page does. In this case you will need to rely on the page_init in your control more than the page_load of your control.

3) You technically can nest user controls, but things will get tricky if you need to start reading and writing information (as in your first question) from any of the nested controls. Also, the page life cycle of the nested controls gets even more important. I would avoid this if you can.

AaronS