473,473 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

UserControl output into an XmlNode

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
existing 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. If you could cc: me on any replies,
that'd be very cool, as I only get the digest version of this list.
And apologies to anyone who already read this on any of the LiveJournal
communities I just asked too ;o)

Thanks!
Owen
--
Owen Blacker, London, GB
--
They that can give up essential liberty to obtain a little temporary
safety deserve neither liberty nor safety -- Benjamin Franklin, 1759
--
Opinions might not even be mine. Other people can go get their own!

Nov 12 '05 #1
1 1257
Ok, I don'think I'm gonna find a convenient way to do it the way I'd
hoped, so I've started thinking about rendering the control into a
Stream and XmlDocument.Load-ing that Stream into my XmlNode hierarchy.

Except I'm not getting anything out using
Control.RenderControl(TextWriter):

public XmlDocument RenderXmlDocument()
{
MemoryStream stream = new MemoryStream();

this.RenderControl(new HtmlTextWriter(new StreamWriter(stream)));

byte[] streamContents = stream.ToArray();
System.Text.StringBuilder sb = new System.Text.StringBuilder();

foreach (byte tmp in streamContents)
sb.Append(Convert.ToChar(tmp));

HttpContext.Current.Trace.Write("EditSectionOrAsse t",
"Rendered control as \n\n[" + sb.ToString() + "]");

XmlDocument control = new XmlDocument();
control.Load(new XmlTextReader(new StreamReader(stream)));

return control;
}

and nothing is getting written to the Trace.

Am I gonna have to work out how to do this without using the control?

Any and all suggestions gratefully received.
Owen
--
Owen Blacker, London, GB
--
They that can give up essential liberty to obtain a little temporary
safety deserve neither liberty nor safety -- Benjamin Franklin, 1759
--
Opinions might not even be mine. Other people can go get their own!

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mahesh Devjibhai Dhola | last post by:
Hi All, I want to make a custom class in c#, which extends System.Xml.XmlNode class of BCL. Now in custom class, I have implement abstract methods of XmlNode class also. Now when I am trying to...
5
by: Mahesh Devjibhai Dhola | last post by:
Hi All, I want to make a custom class in c#, which extends System.Xml.XmlNode class of BCL. Now in custom class, I have implement abstract methods of XmlNode class also. Now when I am trying to...
8
by: Raed Sawalha | last post by:
Hi, I have a strange problem with a usercontrol on a page. The usercontrol dispalyes three categories (From a database) when the user clicks a category they see all the products in a shop for...
1
by: Owen Blacker | last post by:
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...
0
by: Choi Han Choong | last post by:
Hi, Would like to know if what I am trying to do is possible. I have a usercontrol(ascx) that basically contains a datagrid. I would like to save the output of this usercontrol to a file when...
12
by: Joe | last post by:
Hello All: Do I have to use the LoadControl method of the Page to load a UserControl? I have a class which contains three methods (one public and two private). The class acts as a control...
1
by: Max2006 | last post by:
Hi, I have a user control that shows the contents of potentially big html files. To save the server memory, I try to avoid reading the whole large-file's text into a label or literal...
4
by: andersch | last post by:
Hi I display a xml file with the TreeView control (Windows Forms) on my MainForm. Now, I would like to be able to edit this xml file (XmlElements) when I select a node in this TreeView. For...
6
by: Rolf Welskes | last post by:
Hello, I want to partial cache by using a UserControl. Now I have a file dependency. In msdn I see it is not possible to do it the same way as in a page. The only information is to create a...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.