Visual Studio and .NET Framework Home
Multi-line textbox looses leading line-break
7/31/2008 5:58:25 AM
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.
Visual Studio 2008 (All Products and Editions)
Operating System Language
Steps to Reproduce
Create a page with a multi-line TextBox and a button.
Set the value of the TextBox to: "\n\n\nText".
Click the button.
After postback, the TextBox contains "\n\nText".
After postback, the TextBox should contain "\n\n\nText".
TAP Code (if applicable)
You can indicate your satisfaction with how Microsoft handled this issue by completing this quick
3 question survey
to post a comment.
Please enter a comment.
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.
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.
Visual Studio Product Team
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.
to post a workaround.
Please enter a workaround.
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 || '\n' == this.Text)
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.
© 2014 Microsoft