开发者

filling a textarea with html and show &lt; and not <

I have built a lit开发者_如何转开发tle editor for resource files.

So I show the content of a resource item in a textarea.

<textarea cols="85" rows="12" id='EditItemTextArea'><%# Eval("Translation")%></textarea>

However, that content is shown as html symbols, so when I load &lt; in the textarea and i look at the source, I see &lt; like this:

<textarea cols="85" rows="12" id='EditItemTextArea'>consumption.&lt;br&gt;&lt;br&gt;</textarea>

But in the textarea (in the browser) a < is shown, and when I save the content of the textarea, I read < and not &lt;

Is there a way to solve this?


Have you tried HttpUtility.HtmlEncode (and HttpUtility.HtmlDecode to get a decoded HTML back)? Your code could look like the following:

<textarea cols="85" rows="12" id='EditItemTextArea' name='EditItemTextArea'><%# System.Web.HttpUtility.HtmlEncode(Eval("Translation").ToString())%></textarea>

Code-behind:

string html = System.Web.HttpUtility.HtmlDecode(base.Request["EditItemTextArea"]);


The HttpUtility.HtmlEncode and HttpUtility.HtmlDecode methods should be of use here.

I'm not sure if I understand you correctly, this you might also try this:

<textarea cols="85" rows="12" id='EditItemTextArea'><%# HttpUtility.Decode(Eval("Translation").ToString())%></textarea>


populating a textarea with special characters

Displaying HTML and other code in a Textarea in ASP.NET


Take a look at System.Web.HttpUtility class. Guess HtmlEncode and HtmlDecode methods helps you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜