Fiona

Fiona

  • NA
  • 8
  • 0

Adding a control to a placeholder at the top of page from a custom control further down the page

Apr 27 2007 12:05 AM

I have a page (index.aspx) which has, in the <head>..</head> section, a placeholder:
<asp:PlaceHolder runat="server" ID="plcMeta" />
This placeholder is designed to hold links to CSS stylesheets as required by the content of the page.

The body of the page is generated by using an XML file. The file may contain a section thus:

<outline style="theme1">
<headers>
 <header text="this is a header"/>
 <header text="this is another header" style="headerstyle1"/>
</headers>
</outline>

index.aspx.cs reads the XML and if there's a style attribute at the outline level, it will create a new MetaHeader object and add it to the plcMeta PlaceHolder:

plcMeta.Add(new MetaHeader("Theme",style);

MetaHeader is a custom class inheriting from UserControl, which renders a <link rel..../> tag.

The index.aspx page contains a custom repeater, which inherits from WebControls.Repeater - for each <header> element in the XML, it will use the repeater's ItemTemplate to call headerItem.ascx, which will then render a <div class="headerItemClass">text from the XML</div>

At this state, i would like to be able to see if the RepeaterItem contains a style in the DataItem and, if so, add another MetaHeader control to the PlaceHolder. This all "works" in as much as if I output the number of controls in plcMeta before and after I add this style, the count has been incremented, and therefore the control has been added, but the second stylesheet doesn't appear in the HTML output. I guess this problem is to do with the order things are rendered - so my question is, how do I add a control to a placeholder at the top of index.aspx from a custom control further down the page?

Thanks!