Home Dashboard Directory Help

Multi-line textbox looses leading line-break by Richard Deeming


 as Fixed Help for as Fixed

Sign in
to vote
Type: Bug
ID: 359023
Opened: 7/31/2008 5:58:25 AM
Access Restriction: Public
User(s) can reproduce this bug


A multi-line TextBox or HtmlTextArea with a value which starts with one or more line-breaks looses the first line break on post-back.
Sign in to post a comment.
Posted by Microsoft on 7/15/2009 at 2:59 PM
Hi Richard, we have fixed this issue. You will see the fix first appear in ASP.NET 4 Beta 1.
Posted by Microsoft on 8/1/2008 at 1:26 AM
Thanks for your feedback. We are escalating this bug to the product unit who works on that specific feature area. The team will review this issue and make a decision on whether they will fix it or not for the next release.

Thank you,
Visual Studio Product Team
Posted by Richard Deeming on 7/31/2008 at 6:06 AM
I have uploaded a sample file. Load the "TestLineBreak.aspx" page, and click the button. Each time you click the button, the text will move up one line.

Internet Explorer, Firefox and Opera all ignore the first line break after the textarea tag, unless it is preceded by another character. For example, if the text is set to " \n\n\nText" (a single space before the line break), the text doesn't move up.

The solution seems to be to render an extra line break before the value of the control if the value starts with a CR or LF.
Sign in to post a workaround.
Posted by Richard Deeming on 7/31/2008 at 6:12 AM
Use a custom TextBox, and change the Render method to:

protected override void Render(HtmlTextWriter writer)
    if (this.TextMode == TextBoxMode.MultiLine)
        if ('\r' == this.Text[0] || '\n' == this.Text[0])
        HttpUtility.HtmlEncode(this.Text, writer);

The downside of this approach is that the TextBox control will always store its text in ViewState if you use a derived control. Changing this behaviour in a derived class without breaking existing code will require reflection, as this is the only way to determine whether the TextChanged event has any subscribers.