Opinions please - using placeholders vs inheriting for multiple presentation

A

Alan Silver

Hello,

I am displaying product details on a page and am allowing the site owner
to specify the style in which the product details are displayed. I am
debating which of two approaches to use here and would appreciate some
comments. I intend to write a control that handles the actual display.
This control would have a method that gets passed the product ID and the
display style ID. It would pull the product details from a database and
display them according to the style specified.

The two current ideas are ...

1) write a ShowProduct class that handles the work and have various
..ascx files inherit this class. That way, each display style can be
handled by one .ascx file, and they can all have the same named control
for (say) the product name. This means the class can just set the
product name control to the right value and know that whichever .ascx is
being used will display it as it wants.

2) have just the one .ascx file that handles all display styles. This
would have a placeholder control for each display style, and would set
the appropriate one to be visible.

Any comments? The first approach involves maintaining more files, but
requires the calling page to work out which control to use and load it
dynamically at run time. The second approach seems simpler, but would
require the (say) product name control for each style to be given a
unique name, resulting in a lot of duplicate code.

Any comments appreciated. TIA
 
G

Guest

I would definitely not do the placeholders idea. That (if I understand your
idea) would make issues come up when you decided to add new styles or styles
conflict in some way. Having all your eggs in one basket may be difficult to
manage later.

The other way seems more work. However, you could minimize a lot of the code
by making an abstract user control class that each new style inherits. It
itself would inherit System.Web.UI.UserControl and bring all the behaviors
with it. Then add .ascx files and change the inheritance from UserControl to
your new control.

Does this make sense?
 
A

Alan Silver

I would definitely not do the placeholders idea. That (if I understand your
idea) would make issues come up when you decided to add new styles or styles
conflict in some way. Having all your eggs in one basket may be difficult to
manage later.

Funnily enough, that's exactly what I found when I tried it!! My initial
thought was that it was going to be easier than the other approach, but
it got messy right from the start.

On the other hand...
The other way seems more work. However, you could minimize a lot of the code
by making an abstract user control class that each new style inherits. It
itself would inherit System.Web.UI.UserControl and bring all the behaviors
with it. Then add .ascx files and change the inheritance from UserControl to
your new control.

I tried this yesterday and was amazed at how easy it was. This is the
first time I've done a class with multiple presentation files, but it
was really easy to do. The only pain was typing in "protected Label
lblFerret;" for every control. That took some time, but other than that,
it was really easy. I can now add extra design styles by simply creating
a new .ascx file. To save time and errors, I hacked an existing one down
to just the controls and then rearranged these into a new design.
Does this make sense?

Perfect. I must say I'm constantly knocked out by how powerful ASP.NET
is. I'm still new enough at it to be very excited (don't worry, I'll
calm down eventually). I've only been doing it a couple of months, and
am still finding my way around, but I have become so productive with it,
that I can't imagine doing any of this in Classic ASP. I'm sure most of
it could have been done, but I wouldn't like to think how!!

Thanks for the reply.
 
C

Clint Hill

Glad to help.

Clint Hill

Alan said:
Funnily enough, that's exactly what I found when I tried it!! My initial
thought was that it was going to be easier than the other approach, but
it got messy right from the start.

On the other hand...



I tried this yesterday and was amazed at how easy it was. This is the
first time I've done a class with multiple presentation files, but it
was really easy to do. The only pain was typing in "protected Label
lblFerret;" for every control. That took some time, but other than that,
it was really easy. I can now add extra design styles by simply creating
a new .ascx file. To save time and errors, I hacked an existing one down
to just the controls and then rearranged these into a new design.



Perfect. I must say I'm constantly knocked out by how powerful ASP.NET
is. I'm still new enough at it to be very excited (don't worry, I'll
calm down eventually). I've only been doing it a couple of months, and
am still finding my way around, but I have become so productive with it,
that I can't imagine doing any of this in Classic ASP. I'm sure most of
it could have been done, but I wouldn't like to think how!!

Thanks for the reply.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top