I have some string values in a dataset. In my composite control, in RenderContent I add dataset values to html table cells using span tags. It works great until I have an xml string in my dataset.
In my RenderControl I have code something like:
output.Write(@"<span id=""valueSpan{0}"" action=""edit"" type=""text"">{1}</span>", this.ID + row["ID"], row["Value"]);
row[“Value”] contains string value of:
<?xml version="1.0" encoding="utf-8"?><testdata>need to display this xml string in span</testdata>
The result I see is “need to display this xml string in span” not the XML data as “<?xml version="1.0" encoding="utf-8"?><testdata>need to display this xml string in span</testdata>“. I think I need to let html know that this is just a value. But how???
You’ll need to escape the
<and>characters, transforming them to their corresponding character entities<and>. Use Server.HtmlEncode() to do this for you:(Also, note that I removed the concatenation
this.ID + row["ID"]in favor of a string.Format() style syntax.)