TextBox problem - Line breaks on long lines?

\r\n in the middle of long lines, line breaks in long lines

Page 1 of 1

8 Replies - 5762 Views - Last Post: 29 January 2010 - 01:49 PM Rate Topic: -----

#1 Imdsm   User is offline

  • D.I.C Regular
  • member icon

Reputation: 104
  • View blog
  • Posts: 362
  • Joined: 21-March 09

TextBox problem - Line breaks on long lines?

Posted 28 January 2010 - 11:48 AM

Having a bit of trouble and so far Google has come up blank in terms of answers, I don't have any code to post as it really isn't relative the the problem, but basically I'm having some trouble with text boxes and line breaks.

The problem is that if I have a multi-line text box and enter a line into it which is too long (therefore gets broken onto the next line), ASP.NET is putting \r\n in between the break.

For example, if I want to put into a box:

[ url ]http://www.domain.co...amegoeshere.png[ /url ]

but the box is so small, it comes out like this:

|--------------------------------------------------| <- size of the box
[ url ]http://www.domain.com/images/very
longimagenamegoeshere.png[ /url ]

then ASP.NET gives me this:

"[ url ]http://www.domain.co...amegoeshere.png[ /url ]"

Which is quite a problem when trying to parse it etc. It could just be that I've overlooked a property somewhere, but I'm really stumped on this.

I'm just wondering if anyones had this problem before, and if you found a easy property to disable it, before I go ahead and code some sort of parse-fixer class.

Anyone?

Is This A Good Question/Topic? 0
  • +

Replies To: TextBox problem - Line breaks on long lines?

#2 eclipsed4utoo   User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1535
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: TextBox problem - Line breaks on long lines?

Posted 28 January 2010 - 01:24 PM

I don't know if there is a way to stop it from happening, but a simple way of getting around it is this...

string input = TextBox1.Text.Replace("\r\n", "");


Was This Post Helpful? 0
  • +
  • -

#3 Imdsm   User is offline

  • D.I.C Regular
  • member icon

Reputation: 104
  • View blog
  • Posts: 362
  • Joined: 21-March 09

Re: TextBox problem - Line breaks on long lines?

Posted 28 January 2010 - 02:05 PM

View Posteclipsed4utoo, on 28 Jan, 2010 - 12:24 PM, said:

I don't know if there is a way to stop it from happening, but a simple way of getting around it is this...

string input = TextBox1.Text.Replace("\r\n", "");



Thanks, but this then breaks any formatting, such as:

Line 1

Line 3

Line 5

->

Line 1 Line 3 Line 5
Was This Post Helpful? 0
  • +
  • -

#4 eclipsed4utoo   User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1535
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: TextBox problem - Line breaks on long lines?

Posted 28 January 2010 - 03:59 PM

the "\r\n" is a line break. removing it will remove the line break. If you want to keep the line break, then you keep it. if you want to display the data in a label, replace "\r\n" with "<br />".
Was This Post Helpful? 0
  • +
  • -

#5 Imdsm   User is offline

  • D.I.C Regular
  • member icon

Reputation: 104
  • View blog
  • Posts: 362
  • Joined: 21-March 09

Re: TextBox problem - Line breaks on long lines?

Posted 28 January 2010 - 05:54 PM

Well you see the reason I need to remove only the faux-breaks is because it breaks urls (as you've seen in my OP), when it comes to displaying it, the image tag becomes:

<img src="http://www.domain.com/images/nam<br />e.jpg" />

Which, of course, doesn't work.

That's why I'm asking here for constructive answers to whether or not the line-breaks can be disabled from appearing in the wrong places, as it's not an option to say "all or nothing".

Thank you for your effort though, but I will continue my search for a fix.
Was This Post Helpful? 0
  • +
  • -

#6 eclipsed4utoo   User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1535
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: TextBox problem - Line breaks on long lines?

Posted 28 January 2010 - 06:21 PM

View PostImdsm, on 28 Jan, 2010 - 08:54 PM, said:

Well you see the reason I need to remove only the faux-breaks is because it breaks urls (as you've seen in my OP), when it comes to displaying it, the image tag becomes:

<img src="http://www.domain.com/images/nam<br />e.jpg" />

Which, of course, doesn't work.

That's why I'm asking here for constructive answers to whether or not the line-breaks can be disabled from appearing in the wrong places, as it's not an option to say "all or nothing".

Thank you for your effort though, but I will continue my search for a fix.


You are basically asking to not put line breaks in a multi-line textbox, which kind of defeats the purpose of a multi-line textbox. If you don't want the line breaks, then use a single-line textbox.
Was This Post Helpful? 0
  • +
  • -

#7 Imdsm   User is offline

  • D.I.C Regular
  • member icon

Reputation: 104
  • View blog
  • Posts: 362
  • Joined: 21-March 09

Re: TextBox problem - Line breaks on long lines?

Posted 29 January 2010 - 08:49 AM

View Posteclipsed4utoo, on 28 Jan, 2010 - 05:21 PM, said:

View PostImdsm, on 28 Jan, 2010 - 08:54 PM, said:

Well you see the reason I need to remove only the faux-breaks is because it breaks urls (as you've seen in my OP), when it comes to displaying it, the image tag becomes:

<img src="http://www.domain.com/images/nam<br />e.jpg" />

Which, of course, doesn't work.

That's why I'm asking here for constructive answers to whether or not the line-breaks can be disabled from appearing in the wrong places, as it's not an option to say "all or nothing".

Thank you for your effort though, but I will continue my search for a fix.


You are basically asking to not put line breaks in a multi-line textbox, which kind of defeats the purpose of a multi-line textbox. If you don't want the line breaks, then use a single-line textbox.


The problem I had was that I wanted only certain line-breaks, as you can see from my OP, I had a problem whereas longer lines were getting \r\n's in them after they were wrapped down onto the next line, a problem I suspected was the textbox, turned out to be a class attached to it, but the problem remained the same.

To summarise, any string longer than x chars was split in half and had a line break inbetween it - this wasn't wanted - however the line breaks from pressing enter were.

"thisisaverylongstringthatdoesntuseanyspacesetc\r\n
this is line 2\r\n
this is line 3"

became

"thisisavery\r\n
longstringth\r\n
atdoesntuse\r\n
anyspacese\r\n
tc\r\n
this is line 2\r\n
this is line 3"

Anyway, sorted it now, but thanks anyway!
Was This Post Helpful? 0
  • +
  • -

#8 eclipsed4utoo   User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1535
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: TextBox problem - Line breaks on long lines?

Posted 29 January 2010 - 09:08 AM

so what did you do? for those who might want to fix this problem if they have it.
Was This Post Helpful? 0
  • +
  • -

#9 Imdsm   User is offline

  • D.I.C Regular
  • member icon

Reputation: 104
  • View blog
  • Posts: 362
  • Joined: 21-March 09

Re: TextBox problem - Line breaks on long lines?

Posted 29 January 2010 - 01:49 PM

View Posteclipsed4utoo, on 29 Jan, 2010 - 08:08 AM, said:

so what did you do? for those who might want to fix this problem if they have it.


Removed a class which broke long strings into multiple lines before feeding it to the page (to avoid stretches / overflown data)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1