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 <
in the textarea and i look at the source, I see <
like this:
<textarea cols="85" rows="12" id='EditItemTextArea'>consumption.<br><br></textarea>
But in the textarea (in the browser) a <
is shown, and when I save the content of the textarea, I read <
and not <
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.
精彩评论