0

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?

avrahamcool
  • 13,888
  • 5
  • 47
  • 58

2 Answers2

3

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.

lestersconyers
  • 354
  • 2
  • 9
  • I've tried it, and it worked. I wasn't able to use the **HtmlTextWriter** _WriteBeginTag_ / _WriteEndTag_ because calling base.Render() messed up the DOM. so I used simple strings instead _
    _ etc.
    – avrahamcool Sep 08 '13 at 08:13
0

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.

Dharmesh
  • 560
  • 1
  • 6
  • 16