Custom controls settings, best practice question

  • Thread starter Thread starter Laurent Bugnion
  • Start date Start date
L

Laurent Bugnion

Hi,

I like to develop custom controls for a number of webpages. These
controls are often customizable, so that they can be reused in a number
of situations.

My question is: What is the best practice for configuring a custom
control. As far as I can say, I have the following alternatives:

- Defining properties for the control, and setting these in the ASPX
page where the control is included (this is what I do now). This has the
advantage that the settings are defined in the same file as the control
itelf, only one file to manage. However, when there are many settings,
one might lose the overview. Also, these properties are parsed on every
roundtrip, so it's not really efficient.

- Using a settings section in web.config. This has the advantage that
settings are not parsed on every roundtrip.

- A mix of these two solutions.

What are your thoughts?

Greetings,
Laurent
 
If the setting are "set 1 time" for the majority of cases..
then I'd go with a custom configuration section/custom handler.

If the property(ies) are going to change for each page that has an
instance(s) of your control, use a property, and set it on the page_load.

If your "set 1 time" is the case most of the time, then use the custom
config section, but add a property so a specific page (using your control)
can override the default setting.

.....

Once you get used to (and getting past your first one) .. to using custom
config sections... you'll end up liking them I think.

spaces.msn.com/sholliday/

check my smtp configuration tool, I have a custom config section/handler
written there.

make sure you put a break point on the handler itself (.Create method?) so
you can see it parsing the xml to create the concrete objects.

...
 
Hi,
If the setting are "set 1 time" for the majority of cases..
then I'd go with a custom configuration section/custom handler.
Yes.


If the property(ies) are going to change for each page that has an
instance(s) of your control, use a property, and set it on the page_load.

That's what I currently do.

If your "set 1 time" is the case most of the time, then use the custom
config section, but add a property so a specific page (using your control)
can override the default setting.

I will have properties anyway, because of the flexibility they offer.
Once you get used to (and getting past your first one) .. to using custom
config sections... you'll end up liking them I think.

I know how to do config sections, I use them already for other purposes
(Page). My question was related to custom controls specifically. What I
like in my current solution is that the custom control's definition is
in one place only, and that's the ASPX page, but I am not against your
suggestions at all.

Thanks for your input!

Greetings,
Laurent
 
Back
Top