User Controls, Web Parts and Image Controls



I've been tasked with the not-enviable job of creating an application
with multiple, semi-customizable templates. My basic concept, thus far,
has been a combination of Master Pages (for layout) and WebPartZones.

Each master page implements an interface (call it IMasterPage), which
provides public properties for the WebPartManager and 3 WebPartZones.
(Rule #1 was static number of zones.)

However, each template can have these zones be different sizes. And I
want my content to be somewhat fluid in this regard. Not really a
problem most of the time; just use percentages. Except on pictures.

Because of the way the app is designed, the images (upon upload into
the system) resize themselves four ways (640px wide, 480px wide, 320px
wide and 160px wide, height proportional). I want to ascertain the
width of the control's containing zone and use the appropriate image,
changing not only the ImageUrl property, but also the Height and Width

BTW, this is all in an .ascx-based UserControl, which is then being
dynamically loaded into the appropriate WebPartZone at run-time.

I'd think the answer would be simple ... But it's not. The UserControl,
naturally, has no idea what it's held in, so I've ensured that all my
webpart-to-be controls implement an interface (call it
IWebPartUserControl) which provides a Resize method (taking a width).

At the point when the page determines which Master Page template to use
(PreInit event), it populates the WebPartZones dynamically. At the
point of loading the control (LoadControl) but before adding it into
the Zone (AddPart), I use this Resize method with the Zone's width.
This Resize method determines the appropriate image and size, and
changes the Image control's properties to suit.

But it never gets reflected in the output HTML. The image tag is
emitted, but it is empty (because ImageUrl is empty in the ascx), and
none of the resize work seems to affect anything. (Using Trace, I was
able to ascertain that it WAS, at least, being performed.)

I've tried adding the web parts and resizing in Page_Load, Page_Init
and Page_PreInit. In Load and Init, the web parts all load but the
resizing has no effect. In PreInit, the web parts don't even bloody

Any help here? Am I stuck doing custom WebPart implementations and
manually coding all the work?





It would appear that I'm stuck manually coding the whole kit and
kaboodle. Which is fine, I guess ... But it appears that once again,
ASP.NET 2.0 makes the easy stuff absurdly easy, and anything even
_slightly_ more complicated absurdly difficult.


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