Show XML string in html SPAN tag -


i have string values in dataset. in composite control, in rendercontent add dataset values html table cells using span tags. works great until have xml string in dataset.

in rendercontrol have code 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 display xml string in span</testdata> 

the result see "need display xml string in span" not xml data "<?xml version="1.0" encoding="utf-8"?><testdata>need display xml string in span</testdata>". think need let html know value. how???

you'll need escape < , > characters, transforming them corresponding character entities &lt; , &gt;. use server.htmlencode() you:

output.write(    @"<span id=""valuespan{0}{1}"" action=""edit"" type=""text"">{2}</span>",    this.id, row["id"], server.htmlencode(row["value"].tostring()) ); 

(also, note removed concatenation this.id + row["id"] in favor of string.format() style syntax.)


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -