Reputation: 590
I have some text stored in a database:
<p>Hi this is Roht <strong>Singh</strong></p>
When I retrieve it and HTML decode it into a label control it gives me this text:
<p>Hi this is Roht <strong>Singh</strong></p>
My code:
label1.Text = Server.HtmlDecode(ds.Tables[0].Rows[0][0].ToString());
How can I render the text as HTML like so?
Hi this is Roht Singh
Upvotes: 1
Views: 733
Reputation: 590
I have solved it i have htmldecode once more the text and it is working. Ans: Server.HtmlDecode(Server.HtmlDecode(ds.Tables[0].Rows[0][0].ToString()));
Upvotes: 2
Reputation: 10140
It looks like your data is HTML encoded twice. Try decoding it twice:
label1.Text = Server.HtmlDecode(
Server.HtmlDecode(ds.Tables[0].Rows[0][0].ToString()
);
When you take your original data:
&lt;p&gt;Hi this is Roht &lt;strong&gt;Singh&lt;/strong&gt;&lt;/p&gt;
And HTML decode it, you get the following:
<p>Hi this is Roht <strong>Singh</strong></p>
When you HTML decode that result, you get:
<p>Hi this is Roht <strong>Singh</strong></p>
Which should then be rendered as:
Hi this is Roht Singh
Upvotes: 4