Question

I want to create a bunch of Webpart for my website, all the webpart have a common special border around them. so their .ascx looks like:

<div class="my_special_border">
    <div class="web_part_content">
        bla bla
    </div >
</div>

i want to avoid the repetition of the border in each webpart (mainly because its not one "div", but a more complex layout).

I was thinking of webpart inheritance, the base will provide the border, and each inheritent will provide its own content.

so I have a "BaseWebpart", in which I put my special border. How can I make the content of the Derived WebParts to go INSIDE the Base border? I need it to be simple to use, so other developers can add their own webparts by only inheriting from my Base. so basicly, I dont want any special Code in the DerivedWebpart (beside the inheritance)

how can I achive this?

Was it helpful?

Solution

I think you'll have to do this in code behind of the basewebpart. In the basewebpart override the Render method. Before base.Render, write the beginning tags of your 2 divs. After base.render write the end tags.

Then have all of your web parts inherit from BaseWebPart.

DISCLAIMER: I haven't tried this myself so I'm just spitballing here. But I think that will work.

OTHER TIPS

I would have tried using a common Resource file being used by different web parts. In code behind, add the content of the Resource file to the top/bottom of the rendered content as required.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top