Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6078169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:48:10+00:00 2026-05-23T10:48:10+00:00

I’ve noticed a most annoying (possible) bug in ASP.NET MVC’s TextAreaFor HTML helper. For

  • 0

I’ve noticed a most annoying (possible) bug in ASP.NET MVC’s TextAreaFor HTML helper. For some reason, the HTML helper adds a NewLine before any content in the textarea. Apparently, this is to combat the possible issue of an individual’s content beginning with a new line on purpose, and the browser ignoring it as per spec.

However, by adding it, I get the MUCH more annoying bug that now in all of my textareas automatically have an extra line before any content on form load (i.e. this shows up before any content in my field: ). It would appear that something is encoding the “newline” before spitting it out.

Anyone have a workaround for this? I’d expect that the intended behavior is for it to print out

    <textarea>
    Stuff</textarea>

not the

    <textarea>&#13;&#10;Stuff</textarea>

I’m getting…

Edit
Upon further inspection, it appears this is due to my using the AntiXssLibrary for encoding instead of the default HtmlEncoder. I am using version 4.0, and my encoder class method looks like this:

    protected override void HtmlEncode(string value, TextWriter output)
    {
        output.Write(Microsoft.Security.Application.Encoder.HtmlEncode(value));
    }

So my THOUGHT is that since the TagBuilder class, which is called from the TextAreaHelper, HTML encodes the contents of the tag, it is ASSUMING the behavior of the default HTML encoder, but the AntiXssLibrary is more thorough, and thus you see this behavior?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:48:10+00:00Added an answer on May 23, 2026 at 10:48 am

    After doing some code digging, I’ve found that my thought is correct. The MVC3 TextArea HTML Helper uses the TagBuilder class, and does the following:

    tagBuilder.SetInnerText(Environment.NewLine + value);
    

    As SetInnerText calls HttpUtility.Encode on the contents of the argument passed to it, this results in the default encoder being called not just on the actual VALUE, but on this Environment.NewLine as well, meaning that if you aren’t using the default HtmlEncoder (like the AntiXssLibrary instead), there could be some unexpected behavior, like this.

    The fix would be for them to instead call:

    tagBuilder.InnerHtml = Environment.NewLine + HttpUtility.Encode(value);
    

    I have submitted a bug report.

    In the mean time, I am implementing a Javascript onLoad fix to remove the offending encoding from all textareas:

    $("textarea").each(function () { $(this).val($(this).val().trim()); });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
i got an object with contents of html markup in it, for example: string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.