Hello
I've created a user control that takes content from an XML file and renders the content on the page. Fairly straight-forward stuff.
However it's come up that I may need to replace portions of the content based on id with other manual content.
My idea is to expose a repeatable property within the user control's declaration like this:
<my:XmlRenderSource ID="XmlRenderSource1" runat="server" XmlUrl="xml/sample.xml">
<OverrideContent targetId='thingToReplaceId'><p>New Content</p></OverrideContent>
<OverrideContent targetId='thingToReplaceId2'><p>New Content</p></OverrideContent>
</my:XmlRenderSource>
So far I have the following in my userControl (i've trimmed out the useless stuff):
public class OverrideContent
{
public string targetId { get; set; }
}
public class OverrideContentCollection : List<OverrideContent>
{
}
[
ParseChildren(
typeof(OverrideContent),
DefaultProperty = "OverrideItems",
ChildrenAsProperties = true
)
]
public partial class XmlRenderSource : System.Web.UI.UserControl
{
private string xmlUrl = "";
private string xmlUrlBase = "";
public OverrideContentCollection OverrideItems
{
get;
set;
}
// Loads of other code that doesn't matter for this
}
Where on load or pre render I loop through the OverrideContent items and replace portions of the xml before render. I understand how I can do that, but I am having a distinct problem exposing the OverrideContent items as a repeatable property.
I know it can be done, but for the life of me I cannot get it going. If anyone could provide a crash-course on how to do this, I would be eternally grateful.