I have a UserControl called Ad that represents an advertisement. It uses attributes and elements to populate its properties:
<mabel:Ad runat="server" ID="Ad3" Weight="1">
<Title>Fundraise with us!</Title>
<Link>/info/fundraising+ideas</Link>
<Image>fundraise.<ils:Query runat="server" />.jpg</Image>
<Copy>Mabel's Labels' fundraisers are easy and profitable. Sign-up your school or organization.</Copy>
<Action>Sign-Up Now</Action>
</mabel:Ad>
The setting of properties works well because I've used the appropriate attributes:
[ParseChildren(true)]
public partial class Ad : UserControl
{
/// <summary>
/// Gets or sets the title.
/// </summary>
/// <value>The title.</value>
[Required]
[PersistenceMode(PersistenceMode.InnerProperty)]
public string Title { get; set; }
/// <summary>
/// Gets or sets the image.
/// </summary>
/// <value>The image.</value>
[Required]
[PersistenceMode(PersistenceMode.InnerProperty)]
public string Image { get; set; }
...
My problem is that I'd like to parse server controls inside these child elements, such as the <ils:Query/> control shown in the <Image> element of the <mabel:ad xmlns:mabel="#unknown"> control.
Since I'm using the [ParseChildren(true)], these nested controls are not parsed because the elements are being parse as values to be assigned to properties.
The simplest solution I've come up with so far is applying a custom ControlBuilder to this server control, setting [ParseChildren(false)] and having the ControlBuilder set the values of each of the properties using reflection; after parsing the InnerText of each.
There must be a simple way .. ?