473,406 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Xml server control

I could not find the answers for these two questions about in Xml server control

1. Is it possible for control to keep its ViewState? Even if I set EnableViewState = true the control does not seem to keep it, so I have to reload it on each postback

2. How do I display raw xml data? My control displays data with a stylesheet fine
XmlDocument doc = new XmlDocument()
doc.LoadXml (xml)
XslTransform trans = new XslTransform()
trans.Load (Server.MapPath("WalMartManifest2.xslt"))
xmlMain.Document = doc
xmlMain.Transform = trans

If I simply comment out the last line (Transform), no data is displayed..

Thanks

-Stan
Nov 18 '05 #1
2 1620
Hi Stan,

From your description, you're wanting to use the ASP.NET xml Server Control
to display raw xml data in the page's response output rather than use some
certain xsl to transform them into html ,yes?

As this question, I'm afraid such operation is not allowed because each
ASP.NET web page will return as a certain ContentType, such as "text/html",
"text/xml", "image/gif" , "application/ms-excel" ...

By default , an aspx page is rendered as html page and its contenttype is
"text/html". And when we us the Xml Server control on it, we need to
specify a xls file or a XslTransform object to it so as to transform the
giving XmlDocuemnt intoHtml so that the result can be embeded into the
page's output response. If we don't transfer it and want to display raw xml
in the page, that means we want to mix a "text/html" type stream with
"text/xml" data which is apparent not allowed. And that's why the raw xml
data is not displayed. Do you think so?

If you do want to display xml data in page, you have the following means:
1. Change the reponse's ContentType to "text/xml" and then write pure xml
data into the response steam, such as:
XmlDocument doc = new XmlDocument();
DataSet ds = GetDataSet();

doc.LoadXml(ds.GetXml());
XmlDeclaration xmldecl;
xmldecl = doc.CreateXmlDeclaration("1.0","UTF-8",null);

//Add the new node to the document.
XmlElement root = doc.DocumentElement;
doc.InsertBefore(xmldecl, root);

//clear the response's original content
Response.Clear();
Response.ClearContent();
Response.ContentType="text/xml";

doc.Save(Response.OutputStream);
Response.End();

2. Or write out the XmlData As normal string text into a certain control
such as "Literal" or "Label" control, we need to html encode it so as to
display correctly. For example:

XmlDocument doc = new XmlDocument();
DataSet ds = GetDataSet();

string xml = ds.GetXml();
lblXml.Text = HttpUtility.HtmlEncode(xml);

#lblXml is a Label control

These are some of my suggestions. Hope helps.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Nov 18 '05 #2
Hi Stan,

Have you had a chance to check out the suggestions in my last reply or have
you got any further ideas on this issue? If you have anything unclear or if
there're anything else we can help, please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #3

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

Similar topics

12
by: HarveyB | last post by:
I would like to generate non-modal popup windows from ASP.Net code-behind. I have tried using Client Side scripting like "function Test(){ window.open('test.htm',_blank,...
2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
2
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the...
4
by: clintonG | last post by:
Technically speaking, this issue is not about modifying the HTML generated by server controls but preceding the HTML generated by server controls with an HTML control generated on the basis of the...
9
by: AFN | last post by:
I was just dropped into someone else's code (isn't that always so fun?). I can't figure out why a custom validation control's server event function is executing. There is nothing (that I see)...
20
by: Guadala Harry | last post by:
In an ASCX, I have a Literal control into which I inject a at runtime. litInjectedContent.Text = dataClass.GetHTMLSnippetFromDB(someID); This works great as long as the contains just...
7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
5
by: serge calderara | last post by:
Dear all, I am new in asp.net and prepare myself for exam I still have dificulties to understand the difference between server control and HTML control. Okey things whcih are clear are the fact...
2
by: Mike | last post by:
Hi, I am strugling with a simple problem which I can't seem to resolve. I have an asp.net page which contains a server-control (flytreeview, which is a kind of a tree to be exact). The tree is...
3
by: pbd22 | last post by:
Hi. How do I add the runat=server attribute on a buttonfield link dynamically? thanks!
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.