owenblacker (owenblacker) wrote in csharp,

  • Mood:
  • Music:

UserControl output into an XmlNode

Very cheeky of me, having only just joined this community, but may I post an awkward question?

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["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 ...>
         <!-- here would be the output of Asset.ToXml -->
         <My:EditControl .../>

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

Any ideas gratefully received. Thanks!

Cross-posted to owenblacker, csharp and ms_dot_net. Sorry :o)

  • Post a new comment


    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.