views:

79

answers:

3

Should dynamic asp.net controls be avoided at all costs?

In what situations should they be used?

What do you use as their replacement?

A: 

1) Unnecessary complexity always should be avoided.
2) When they are necessary.
3) Lesser complicated options.

Spencer Ruport
Could you expand on all three. Thanks.
+1  A: 

I mostly avoid them if a postback is required. Reconstructing them is a pain. When possible build them inside a <asp:repeater> or other control which can be databound.

Keltex
I agree. Nice answer.
+1  A: 
  1. No
  2. When you don't know until runtime the control you want to instantiate
  3. I am not afraid of dynamic controls..

For rehydrating them on post back I use a DynamicControlsPlaceholder

It's great when you want to bring a control back with it's viewstate without having to reconstruct it yourself on each request.

Chris Lively
Very nice Chris. Thank you.