UserControl output into an XmlNode

An awkward question for any C# geeks reading

In a CMS-like environment, I have a list of items that is generated on the serverside using an XmlDocument to throw together XHTML tags (mainly because it’s substantially easier than using a Repeater, but the why is a moot point as the project doesn’t have the budget for me to change that).

Now I have a requirement to add a new list item at the end of each list that is an “Add new item” form. It’s very easy for me to write a UserControl to handle this form action, but would be relatively difficult to write this form bit as XmlElements to add into the exsiting XmlNode tree.

Is there a way for me to get the output of the server control as an XmlNode and squish that into my XmlNode tree?

Effectively, I want to take my existing code and making it look something like this:

     bool isInAuthoringMode;
     XmlDocument xml;
     XmlElement div;

 5   // ...

     if (isInAuthoringMode || (this.Assets != null &&
         this.Assets.Count > 0)
     {
10      XmlElement ul = xml.CreateElement("ul");
        ul.Attributes.Append(xml.CreateAttribute("class"));
        ul.Attributes["class"].Value = "file-list";

        foreach (Asset a in this.Assets)
15         ul.AppendChild(a.ToXml(xml));

        if (isInAuthoringMode)
           ul.AppendChild(new EditControl().ToXml(xml));

20      div.AppendChild(ul);
     }

Line 18 in this code block is what I’d really like to be able to do, but I know that would be being very optimistic.

Is there any obvious way of getting “the HTML this control would generate here” out of it, even if I have to write a new method into it somewhere?

The behavior I seek is roughly the same as if I had a Repeater like this:

   <asp:Repeater ...>
      <ItemTemplate>
         <!-- here would be the output of Asset.ToXml -->
      </ItemTemplate>
      <FooterTemplate>
         <My:EditControl .../>
      </FooterTemplate>
   </asp:Repeater>

But I can’t use a Repeater (for reasons too tedious to detail here).

Any ideas gratefully received. Thanks!

Cross-posted to , and . Sorry :o)

Advertisements

Ymatebwch

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s